Created
January 9, 2019 03:52
-
-
Save kevinahn7/ad8a4064a78ab4b64c045776c3e41ef7 to your computer and use it in GitHub Desktop.
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
| ['ab', 'c', 'd', 'ba', 'd'] => [['ab', 'ba'], ['c'], ['d', 'd'] | |
| function countAnagrams(stringArray) { | |
| let newArray = []; | |
| for (let i = 0; i < stringArray.length; i++) { | |
| let dontRunLoop = false; | |
| let currentString = stringArray[i]; | |
| for (let j = 0; j < newArray.length; j++) { | |
| if (newArray[j].includes(stringArray[i])) { | |
| dontRunLoop = true; | |
| } | |
| } | |
| if (!dontRunLoop) { | |
| newArray.push([stringArray[x]]) | |
| for (let k = i + 1; k < stringArray.length; k++) { | |
| if (stringArray[k].split("").sort().join("") === currentString.split("").sort().join("")) { | |
| newArray[newArray.length - 1].push(stringArray[k]) | |
| } | |
| } | |
| } | |
| } | |
| return newArray; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment