Consider the following function:
getNewColor(): {} {
return colors.red;
}
Along with this object:
colors: any = {
red: {primary: '#ad2121',secondary: '#FAE3E3'},
blue: {primary: '#1e90ff',secondary: '#D1E8FF'},
yellow: {primary: '#e3bc08',secondary: '#FDF1BA'}
};
Whenever getNewColor()
is called, it should return a new color object from the collection (not repeating any previously returned colors).
If we were to run:
console.log(getNewColor());
console.log(getNewColor());
console.log(getNewColor());
The expected output would be:
{primary: '#ad2121',secondary: '#FAE3E3'}
{primary: '#e3bc08',secondary: '#FDF1BA'}
{primary: '#1e90ff',secondary: '#D1E8FF'}
What is the most effective approach to implement the functionality of getNewColor()
?