const PALETTE = ["#5B8FF9", "#5AD8A6", "#F6BD16", "#E86452"];/** * ========================================================================== * @param startWithColor absent, or one of the colors in PALETTE */function getColorGenerator( startWithColor?: string): Generator<string, string> { // Your code goes here let i = startWithColor ? PALETTE.indexOf(startWithColor) - 1 : -1; return (function* fn() { while (i < PALETTE.length) { i++; if (i === PALETTE.length) { i = 0; } yield PALETTE[i]; } return ''; })();}/** * ========================================================================== * Finish the function * Expected console output: * "#5B8FF9" * "#5AD8A6" * "#F6BD16" * "#E86452" */function main1() { const colorGenerator = getColorGenerator(); for (let i = 0; i < 8; i++) { if (i % 2 !== 0) { continue; } // use colorGenerator to get color, and print it // console.log(color) const color = colorGenerator.next().value; console.log(color); }}main1();/** * ========================================================================== * Finish the function * Expected console output: * "#F6BD16" * "#E86452" * "#5B8FF9" * "#5AD8A6" */function main2() { const colorGenerator = getColorGenerator("#F6BD16"); for (let i = 0; i < 4; i++) { // use colorGenerator to get color, and print it // console.log(color) const color = colorGenerator.next().value; console.log(color); }}main2();