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

Cristian Fernando - May 10 '22 - - Dev Community

Explica este código JavaScript

Dificultad: Avanzado

const datos = [
  {
    id:1,
    nombre:"Ana",
    edad:25
  },
  {
    id: 2,
    nombre: "Cris",
    edad: 26
  },
];

const getDatos = () => {
  return new Promise((resolve, reject) => {
    if(datos.length > 0){
      setTimeout(() => {
        resolve(datos)
      },3000-1000)
    }else{
      reject(new Error("Algo ocurrio mal"))
    }
  })
}

getDatos()
  .then((datos) => console.log(datos.filter((item) => item.edad > 25)
                                    .map((item) => item.edad)))
  .catch((error) => console.log(error.message))
  .finally(() => console.log("FIN"))
Enter fullscreen mode Exit fullscreen mode

A. "Algo ocurrio mal", FIN (después de 3000 ms)
B. [], FIN (después de 2000 ms)
C. [26], FIN (después de 2000 ms)
D. Promise { <pending> } (después de 0 ms)

Respuesta en el primer comentario.


. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .