Currently trying to check if two strings are permutations of one another by sorting both and checking if they are equal - permutations have the same characters, just in different orders. In my example "dog" and "god" are permutations of one another.
I have implemented the below code which I believe is correct. I made changes through looking at why this might be the case online, but I'm still stuck on why i'm getting this error as .equals() seems to be used widely to compare two strings in JavaScript.
The error is:
if (sort(s1).equals(sort(s2))) {
TypeError: sort(...).equals is not a function
function sort(string) {
return string
.split("")
.sort()
.join("");
}
function isPermutation(s1, s2) {
if (sort(s1).equals(sort(s2))) {
return true;
}
return false;
}
console.log(isPermutation("dog", "god"));