Are They The "same"? Codewars
HERE IS THE FULL QUESTION DESCRIPTION Given two arrays a and b write a function comp(a, b) (compSame(a, b) in Clojure) that checks whether the two arrays have the 'same' elements,
Solution 1:
The easiest possible way:
const comp = (a1, a2) => {
if (!a1 || !a2 || a1.length !== a2.length) return false;
return a1.map(x => x * x).sort().toString() === a2.sort().toString();
}
Post a Comment for "Are They The "same"? Codewars"