Hey there! I'm reaching out because I need assistance with a Javascript function:
Basically, I have an input array that I want to compare to another array and based on the result, return something. However, for some reason my comparison is not yielding the correct outcome...
Here's the function in question:
const createArrayColor = (labels) => {
const combi = [
["bronze","gold","new","silver"],
// Other array combinations listed here...
];
const color = [
// Corresponding colors for each combination mentioned above...
];
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;
})
}
(By the way, if you happen to know a better way to create combinations of arrays in JS, please share! I believe there might be a more efficient method than what I've attempted so far)
As evident from the code snippet provided, I am comparing the labels
array with each element within the combi
array, yet the comparison always results in false
...
https://i.sstatic.net/Mp61j.png
I reckon it's just a minor oversight on my part, but alas, I'm unable to pinpoint where I went wrong...