I have a question regarding a function in Javascript:
I simply compare an input array to another and return something depending on the result, but for some reason, my comparison doesn't work...
here's my function:
const createArrayColor = (labels) => {
const combi = [
["bronze","gold","new","silver"],
["bronze","gold","silver"],
["gold","new","silver"],
["bronze","gold","new"],
["bronze","new","silver"],
["gold","silver"],
["bronze","gold"],
["gold","new"],
["bronze","silver"],
["new","silver"],
["bronze","new"],
["gold"],
["silver"],
["bronze"],
["new"],
];
const color = [
["#614E1A","#c49c48", "#f4f3f3", "#A5A49B"],
["#614E1A", "#c49c48", "#A5A49B"],
["#c49c48", "#f4f3f3", "#A5A49B"],
["#614E1A", "#c49c48", "#f4f3f3"],
["#614E1A", "#f4f3f3", "#A5A49B"],
["#c49c48", "#A5A49B"],
["#614E1A", "#c49c48"],
["#c49c48", "#f4f3f3"],
["#614E1A", "#A5A49B"],
["#f4f3f3", "#A5A49B"],
["#614E1A", "#f4f3f3"],
["#c49c48"],
["#A5A49B"],
["#614E1A"],
["#f4f3f3"],
];
let i = 0;
combi.forEach((c) => {
console.log("Color: " + color[i]);
console.log("Combi: " + c + " ,type: " + c.constructor.name );
console.log("labels: " + labels + " ,type: " + labels.constructor.name );
console.log("Is it equal? " + (labels === c));
if (labels === c) {
return color[i];
}
i = i + 1;
})
}
(btw if you know how to make a combination of an array in JS I'd like to know that too, I'm sure there's a better way to do it that what I did but I didn't find it)
So as you can see I compare labels
with each element of combi
, but it is always false
...
I think it's a small mistake I made somewhere but I can't find it...