Created
February 18, 2015 15:10
-
-
Save citylims/bfa67f82d90015ba8dc0 to your computer and use it in GitHub Desktop.
Anagram Detector
This file contains 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
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