I want to compare two string arrays, but case insensitive and independent.
For the example:
['a', 'b', 'c'] === ['A', 'c', 'B'] -> TRUE
['a', 'b', 'c'] === ['a', 'b', 'd'] -> FALSE
TRUE
when they are with the same length and same values (case insensitive ['A'] === ['a'] -> true
) and independent, about ordering ['a', 'b'] === ['b', 'a'] -> true
.
What I did for now is:
areEqual = (arr1, arr2) => {
const equalLength = arr1.length === arr2.length;
return arr2.every(arr2Item => {
return arr1.includes(arr2Item.toLowerCase());
}) && equalLength;
};
, but this is case sensitive
.
I am using JS, ES6
with React
.