Skip to content

Instantly share code, notes, and snippets.

@web20opensource
Created March 24, 2015 16:47
Show Gist options
  • Save web20opensource/9c8bf14ae82793628b40 to your computer and use it in GitHub Desktop.
Save web20opensource/9c8bf14ae82793628b40 to your computer and use it in GitHub Desktop.
Check if the given words are an anagram
(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]));
}
}
})();
@web20opensource
Copy link
Author

Check if a word is an anagram respect to his match.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment