Forked from anonymous/Anagramatic (2.6) Extra Problems.js
Created
July 31, 2016 19:43
-
-
Save sethschori/bcd1049dd1f5f04cad35b638c17d7170 to your computer and use it in GitHub Desktop.
https://repl.it/C1Tp/89 created by sethopia
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
/* | |
Anagramatic | |
Write a function that takes in two strings and determines if they are anagrams of each other. Something is an anagram of something else if it is made up of the same characters. | |
For example ekez is an anagram of zeke. zkee is also an anagram of zeke. | |
Your function should return true or false. | |
anagram('zeke', 'hello world'); | |
// -> false | |
anagram('nick', 'ncki'); | |
// -> true | |
*/ | |
function anagram(word1, word2) { | |
if (word1.length !== word2.length) return false; | |
for (var i = 0; i < word1.length; i++) { | |
if (word2.indexOf(word1.charAt(i)) === -1) return false; | |
} | |
return true; | |
} | |
console.log(anagram('zeke', 'hello world')); | |
console.log(anagram('nick', 'ncki')); | |
console.log(anagram('qo', 'oq')); |
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
Native Browser JavaScript | |
>>> false | |
true | |
true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment