Created
October 18, 2017 03:08
-
-
Save nicholasaiello/b85b5432ee2c7f84f966b0ce13c283b2 to your computer and use it in GitHub Desktop.
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
const words = ['map', 'art', 'how', 'rat', 'tar', 'who', 'pam', 'shoop']; | |
const sortWord = (word) => ( | |
word.split('').sort().join('') | |
); | |
const matches = words.reduce((obj,w) => { | |
if (w) { | |
const k = sortWord(w); | |
if (!(k in obj)) { | |
obj[k] = []; | |
} | |
obj[k].push(w); | |
} | |
return obj; | |
}, {}); | |
console.log(matches); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment