function anagram(str1, str2) { return ( str1.length == str2.length && str1.split("").every(c => str2.includes(c)) && str2.split("").every(c => str1.includes(c)) ); }
... and its still about 70% faster.
Nice :)
The new method returns true for "abb", "aab", I don't think it should.
true
"abb", "aab"
You're right, every just won't work. My method works for a few cases but not all.
every
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
function anagram(str1, str2) {
return (
str1.length == str2.length &&
str1.split("").every(c => str2.includes(c)) &&
str2.split("").every(c => str1.includes(c))
);
}
... and its still about 70% faster.
Nice :)
The new method returns
true
for"abb", "aab"
, I don't think it should.You're right,
every
just won't work. My method works for a few cases but not all.