Created
July 7, 2018 10:11
-
-
Save Kaeyz/36829da7fa16549a51e46aca0f53bde7 to your computer and use it in GitHub Desktop.
anagram: to test if a word is an anagram or not
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
function anagram(str) { | |
let arr = str.split(''); | |
let anaResult, anaValue, response; | |
let finalArr = []; | |
for (let index = 0; index < arr.length; index++) { | |
let cleanNewArray = []; | |
let result = true | |
let resultArr = []; | |
let compare = arr[index]; | |
for (let index = 0; index < arr.length; index++) { | |
if (compare === arr[index]) { | |
result = true | |
} else { | |
result = false | |
} | |
resultArr.push(result) | |
} | |
for (let index = 0; index < resultArr.length; index++) { | |
cleanNewArray = resultArr.filter(function (cleanArray) { | |
return cleanArray === true | |
}) | |
if (cleanNewArray.length > 1) { | |
anaResult = false; | |
} else { | |
anaResult = true | |
} | |
}; | |
finalArr.push(anaResult); | |
} | |
anaValue = finalArr.filter(function (k) { | |
return k !== true | |
}) | |
if (anaValue.length !== 0) { | |
response = false; | |
} else { | |
response = true; | |
} | |
console.log(response); | |
return response; | |
} | |
anagram('abcdefghijklmnopqrstuvwxyz'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment