0
7
:
0
7
:
2
9

Whiteboard 002 - Agrupando anagramas

2019-10-23T00:00:00.000Z

Tienes un arreglo de palabras.

arr=[ ana,   naa,   choo,   fun,   nuf ]arr = [~ ana, \ \ \ naa, \ \ \ choo, \ \ \ fun, \ \ \ nuf ~]
const agrupaAnagramas = (arr) {
	groups = {}

	for (word in arr){
		if(groups[arr[word].split('').sort().join('')] == undefined){
			groups[arr[word].split('').sort().join('')] = [arr[word]];
		}
		else{
			groups[arr[word].split('').sort().join('')].push(arr[word]) 
		}
	}

	return Object.values(groups)
}
agrupaAnagramas(arr)=>[ [ ana,naa ],   [ fun,nuf ],  [ choo ] ]agrupaAnagramas ( arr ) => [~ [~ ana, naa ~], \ \ \ [~ fun, nuf ~], \ \ \, [~ choo ~] ~]

    🐬 O(n)\sim O(n)


último commit por ti.