Created
November 17, 2018 05:40
-
-
Save MacTanomsup/b5de0188fc7424bb687a52ce08b5b5b3 to your computer and use it in GitHub Desktop.
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
| function same(arr1, arr2){ | |
| if(arr1.length !== arr2.length){ | |
| return false; | |
| } | |
| let frequencyCounter1 = {} | |
| let frequencyCounter2 = {} | |
| for(let val of arr1){ | |
| frequencyCounter1[val] = (frequencyCounter1[val] || 0) + 1 | |
| } | |
| for(let val of arr2){ | |
| frequencyCounter2[val] = (frequencyCounter2[val] || 0) + 1 | |
| } | |
| for(let key in frequencyCounter1){ | |
| if(!(key ** 2 in frequencyCounter2)){ | |
| return false | |
| } | |
| if(frequencyCounter2[key ** 2] !== frequencyCounter1[key]){ | |
| return false | |
| } | |
| } | |
| return true | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment