JSFiddle - React, Tailwind, and code Playground
by Ea Bangalore
HTML
<ul></ul>
JavaScript
var names = [
"Bill", "Joe", "Oliver", "Joe", "George", "Bill", "George", "John",'ejaz','anwar','alpha be'];
var currentAssignments = {};
for (var i = 0; i < names.length; i++) {
var name = names[i];
var colour = currentAssignments[name];
if (!colour) {
colour = GetRandomColour();
currentAssignments[name] = colour;
}
var li = $("<li>").html(name).css("color", colour);
$("ul").append(li);
}
function GetRandomColour() {
return '#' + Math.floor(Math.random() * 16777215).toString(16);
}