Solución

@msae986_4294e21c
·hace 1dTypeScript
solution.tsTypeScript
function groupByFirstLetter(words: string[]): Record<string, string[]> {
  const result = new Map();

  words.forEach(word => {
    const firstLetter = word[0].toLowerCase();
    if(!result.get(firstLetter)) result.set(firstLetter, []);
    result.set(firstLetter, [...result.get(firstLetter), word])
  })
  return {...Object.fromEntries(result)};
}

// No modificar: necesario para evaluar el resultado.
export { groupByFirstLetter };
0respuestas
Respuestas
0

Aún no hay respuestas

¡Sé el primero en responder!

Escribir un comentario

Recuerda ser amable. Estás comentando la solución de otra persona. Comparte tu perspectiva de forma constructiva y respetuosa.

Debes iniciar sesión para publicar un comentario.
Markdown