Last active
October 19, 2022 15:34
-
-
Save tiotamara/165cdae1a9bb265a83231a1535cb836f to your computer and use it in GitHub Desktop.
Logic Test
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 anagrams = (arr) => { | |
const result = {} | |
for (value of arr) { | |
const key = value.split('').sort().join('') | |
if (typeof result[key] === 'undefined') { | |
result[key] = [] | |
} | |
result[key].push(value) | |
} | |
return Object.values(result) | |
} | |
const arr = ['cook', 'save', 'taste', 'aves', 'vase', 'state', 'map'] | |
const res = anagrams(arr) | |
console.log(res) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment