DEV Community 👩‍💻👨‍💻

Cristian Fernando
Cristian Fernando

Posted on

Paracetamol.js💊| #2: ¿Qué imprime este código?

¿Qué crees que imprime el siguiente código?

const arreglo = [true, 33, 9, "-2"];

const f = (arr) => {
  return arr.map(Number)
}
const res = f(arreglo)
console.log(res)
Enter fullscreen mode Exit fullscreen mode

a) [1, 33, 9, -2]
b) [boolean, 33, 9, string]
c) [null, 33, 9, null]
d) [undefined, 33, 9, undefined]


Puedes ver la respuesta en el primer comentario.

Top comments (1)

Collapse
 
duxtech profile image
Cristian Fernando

La respuesta es:
a) [1, 33, 9, -2]
¿Por qué?
El objeto Number de javascript puede convertir los los valores de un arreglo a números, pero hay que tener cuidado con tipos boolean, undefined o null.
Este hack es muy útil cuando tenemos un arreglo de strings que queremos convertir a números.

Timeless DEV post...

How to write a kickass README

Arguably the single most important piece of documentation for any open source project is the README. A good README not only informs people what the project does and who it is for but also how they use and contribute to it.

If you write a README without sufficient explanation of what your project does or how people can use it then it pretty much defeats the purpose of being open source as other developers are less likely to engage with or contribute towards it.