Created
August 8, 2022 16:24
-
-
Save sridhar02/cba09bc9c47e0202161658535a4f7189 to your computer and use it in GitHub Desktop.
Codewars Are they the "same"? Javascript solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* codewars exercise | |
* https://www.codewars.com/kata/550498447451fbbd7600041c/train/javascript | |
*/ | |
function comp(array1, array2) { | |
//your code here | |
let result = false; | |
if (!array1 || !array2 || array1.length !== array2.length) { | |
result = false; | |
} else { | |
const squareArray = array1.map((elem) => elem * elem); | |
result = array2.every((elem) => { | |
return squareArray.includes(elem); | |
}); | |
} | |
return result; | |
} | |
let arr1 = [5, 7, 1, 7, 1, 0, 3, 0, 1, 5, 0, 3, 6, 10, 3, 4]; | |
let arr2 = [1, 36, 25, 0, 100, 1, 9, 0, 9, 49, 9, 25, 1, 1, 49, 16]; | |
// this case should fail as per codewars test case not sure why | |
console.log(comp(arr1, arr2)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment