Last active
January 10, 2017 22:54
-
-
Save jmahc/879bdd56b8424e6db5c1664001ab3cc8 to your computer and use it in GitHub Desktop.
JavaScript method that determines if two string values are anagrams.
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 anagram(wordOne, wordTwo) { | |
var isAnagram = false; | |
if (wordOne.split('').length === wordTwo.split('').length) { | |
wordOne.split('').sort().every(function(one, two) { | |
return isAnagram = one === wordTwo.split('').sort()[two]; | |
}); | |
} | |
return isAnagram; | |
} | |
console.log(anagram("jordan", "najorad")); |
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 anagram(wordOne, wordTwo) { | |
if (wordOne.split('').length === wordTwo.split('').length && wordOne.split('').sort().every(function(one, two) { return one === wordTwo.split('').sort()[two]; })) { | |
return true; | |
} | |
return false; | |
} | |
console.log(anagram("jordan", "najord")); |
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 anagram(wordOne, wordTwo) { | |
return wordOne.split('').length === wordTwo.split('').length && wordOne.split('').sort().every(function(one, two) { return one === wordTwo.split('').sort()[two]; }) ? true : false; | |
} | |
console.log(anagram("jordan", "najord")); |
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 anagram(wordOne, wordTwo) { | |
var isAnagram = false; | |
if (wordOne.split('').length === wordTwo.split('').length) { | |
wordOne.split('').sort().every(function(one, two) { | |
one === wordTwo.split('').sort()[two] ? isAnagram = true : isAnagram = false; | |
}); | |
} | |
return isAnagram; | |
} | |
console.log(anagram("test", "etts")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment