Are they the same?
This commit is contained in:
12
are-they-the-same/index.js
Normal file
12
are-they-the-same/index.js
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
// https://www.codewars.com/kata/are-they-the-same/train/javascript
|
||||||
|
|
||||||
|
function comp(a1, a2) {
|
||||||
|
if (!a2) return false;
|
||||||
|
for (let i = 0; i < a1.length; ++i) {
|
||||||
|
let n = a1[i] * a1[i];
|
||||||
|
let idx = a2.indexOf(n);
|
||||||
|
if (idx < 0) return false;
|
||||||
|
a2.splice(idx, 1);
|
||||||
|
}
|
||||||
|
return (a2 || []).length === 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user