Created
March 24, 2015 16:47
-
-
Save web20opensource/9c8bf14ae82793628b40 to your computer and use it in GitHub Desktop.
Check if the given words are an anagram
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(){ | |
var first_words = ["iceman","animal"]; | |
var second_words = ["cinema","lamina"]; | |
check_anagrams(first_words, second_words); | |
function check_anagrams(first_words, second_words) { | |
// To print results to the standard output please use console.log() | |
// Example: console.log("Hello world!"); | |
function anagram(first_word,second_word){ | |
firstArr = first_word.split(''); | |
secondArr = second_word.split(''); | |
firstArr.sort(); | |
secondArr.sort(); | |
for (var i=0 ; i< firstArr.length ; i++){ | |
if (firstArr[i]===secondArr[i]); | |
else | |
return false; | |
} | |
return true; | |
} | |
for (var i=0 ; i<first_words.length ; i++){ | |
console.log(anagram(first_words[i], second_words[i])); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Check if a word is an anagram respect to his match.