Created
March 27, 2019 06:15
-
-
Save IAMIronmanSam/b5383997482bc8f4ce1dcb805034de46 to your computer and use it in GitHub Desktop.
This file contains 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 (string1,string2){ | |
let FC1 = {}; | |
let FC2 = {}; | |
//Short Circuit if length is differnt | |
if(string1.length !== string2.length){ | |
return false; | |
} | |
//Categorize the input data to compare | |
for(let val of string1){ | |
FC1[val] = (FC1[val]||0)+1; | |
} | |
//Categorize the input data to compare | |
for(let val of string2){ | |
FC2[val] = (FC2[val]||0)+1; | |
} | |
console.log(FC1); | |
console.log(FC2); | |
//Comapre both object by key & value | |
for(let key in FC1 ){ | |
console.log(key,FC1[key]); | |
if(!(key ** 2 in FC1) || FC2[key ** 2] !== FC1[key]){ | |
return false; | |
} | |
} | |
return true; | |
} | |
same([1,2,1],[1,5,1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment