JSFiddle - React, Tailwind, and code Playground
JavaScript
/**
* ******************************************************************************************
* Generate random colors array
* ******************************************************************************************
*/
function genRandomColorsArray(arrayLength) {
// Create an empty array to store the colors
let colorsArray = [];
// Loop over the array length
for (let i = 0; i < arrayLength; i++) {
// Generate a random rgb color
let randomColor = genRandomRgbColor();
// Check if the color already exists
while (colorsArray.includes(randomColor)) {
// If the color already exists, generate a new one
randomColor = genRandomRgbColor();
}
// Add the new color to the array of colors
colorsArray.push(randomColor);
}
return colorsArray;
}