Last active
November 30, 2016 20:01
-
-
Save arthurvasconcelos/42ac0499aa93fa9e8f8245dadf03cc1c 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
input = ['bike', 'kibe', 'foo', 'face', 'cafe', 'lua', 'ula', 'lau', 'ok']; | |
// dado o input, imprimir | |
// bike kibe | |
// foo | |
// face cafe | |
// lua lau ula | |
// ok | |
// em qq ordem, desde que os anagramas estejam juntos na mesma linha | |
var ana = {}; | |
for (var i = 0; i < input.length; i++) { | |
// var tmp = input[i].split('').sort().join(''); | |
// ana[tmp] = []; | |
// for (var j = 0; j < input.length; j++) { | |
// if (tmp === input[j].split('').sort().join('')) { | |
// ana[tmp].push(input[j]); | |
// } | |
// } | |
// =================== | |
var tmp = input[i].split('').sort().join(''); | |
// if (!ana[tmp]) { | |
if (!(tmp in ana)) { | |
ana[tmp] = [] | |
} | |
ana[tmp].push(input[i]); | |
} | |
console.log(ana); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment