DEV Community

Cristian Fernando
Cristian Fernando

Posted on

3 3

Paracetamol.js💊| #145: Explica este código JavaScript

Explica el siguiente código JavaScript

Dificultad: Intermedio

const x = (arr) => {
  return arr.flatMap((item) => [...item])
}

console.log(x(["Hola", "mundo"]));
Enter fullscreen mode Exit fullscreen mode

A. [ "H", "o", "l", "a", "m", "u", "n", "d", "o" ]
B. ["Hola", "mundo"]
C. [["Hola"], ["mundo"]]
D. Ninguna de las anteriores

Respuesta en el primer comentario.


Top comments (3)

Collapse
 
duxtech profile image
Cristian Fernando

Respuesta:
[ "H", "o", "l", "a", "m", "u", "n", "d", "o" ]

flatMap aparte de transformar cada elemento del arreglo también es capaz de poder aplanarlo, es una fusión entre los métodos map y flat de JavaScript.

El ejemplo presenta una manera de poder separar cadenas en caracteres individuales usando flatMap.

Collapse
 
taneros profile image
Renatik

la respuesta es A. ? y porque el primer elemento aqui esta en minusculo ?

Collapse
 
duxtech profile image
Cristian Fernando

lo revisaré

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay