Skip to content

Instantly share code, notes, and snippets.

@citylims
Created February 18, 2015 15:10
Show Gist options
  • Save citylims/bfa67f82d90015ba8dc0 to your computer and use it in GitHub Desktop.
Save citylims/bfa67f82d90015ba8dc0 to your computer and use it in GitHub Desktop.
Anagram Detector
var array = ["enlists", "google", "inlets", "banana"];
function anagram(word, array) {
var word = word.split('').sort().join('');
for(var i = 0; i < array.length; i++) {
var checking = (array[i].split('').sort().join(''));
word === checking ? console.log(array[i], true) : false;
}
}
anagram("listen", array);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment