Skip to content

Instantly share code, notes, and snippets.

@nicholasaiello
Created October 18, 2017 03:08
Show Gist options
  • Save nicholasaiello/b85b5432ee2c7f84f966b0ce13c283b2 to your computer and use it in GitHub Desktop.
Save nicholasaiello/b85b5432ee2c7f84f966b0ce13c283b2 to your computer and use it in GitHub Desktop.
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