This content originally appeared on DEV Community and was authored by Cristian Fernando
Explica este código JavaScript
Dificultad: Intermedio
const getName = (name) => {
return new Promise ((resolve, reject) => {
setTimeout(() => {
resolve(name)
},3000)
})
}
const getAge = (age) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (age < 18) reject(new Error(`${age} no es edad valida`))
}, 2000)
})
}
const counterFriends = (friends) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(friends.length)
}, 5000)
})
}
const getPromises = () => {
const arr = [
getName("Pepe"),
getAge(15),
counterFriends(["Ana", "Roberto", "Juan"])];
return Promise.any(arr)
.then((response) => {
console.log(response)
})
.catch(err => console.log(err))
}
getPromises()
- A.
15 no es edad valida
- B.
3
- C.
Pepe
- D.
Promise { <pending> }
- E.
["Pepe", "15 no es edad valida", 3]
Respuesta en el primer comentario.
This content originally appeared on DEV Community and was authored by Cristian Fernando
Print
Share
Comment
Cite
Upload
Translate
Updates
There are no updates yet.
Click the Upload button above to add an update.
APA
MLA
Cristian Fernando | Sciencx (2023-03-24T15:08:02+00:00) Paracetamol.js💊| #209: Explica este código JavaScript. Retrieved from https://www.scien.cx/2023/03/24/paracetamol-js%f0%9f%92%8a-209-explica-este-codigo-javascript/
" » Paracetamol.js💊| #209: Explica este código JavaScript." Cristian Fernando | Sciencx - Friday March 24, 2023, https://www.scien.cx/2023/03/24/paracetamol-js%f0%9f%92%8a-209-explica-este-codigo-javascript/
HARVARDCristian Fernando | Sciencx Friday March 24, 2023 » Paracetamol.js💊| #209: Explica este código JavaScript., viewed ,<https://www.scien.cx/2023/03/24/paracetamol-js%f0%9f%92%8a-209-explica-este-codigo-javascript/>
VANCOUVERCristian Fernando | Sciencx - » Paracetamol.js💊| #209: Explica este código JavaScript. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2023/03/24/paracetamol-js%f0%9f%92%8a-209-explica-este-codigo-javascript/
CHICAGO" » Paracetamol.js💊| #209: Explica este código JavaScript." Cristian Fernando | Sciencx - Accessed . https://www.scien.cx/2023/03/24/paracetamol-js%f0%9f%92%8a-209-explica-este-codigo-javascript/
IEEE" » Paracetamol.js💊| #209: Explica este código JavaScript." Cristian Fernando | Sciencx [Online]. Available: https://www.scien.cx/2023/03/24/paracetamol-js%f0%9f%92%8a-209-explica-este-codigo-javascript/. [Accessed: ]
rf:citation » Paracetamol.js💊| #209: Explica este código JavaScript | Cristian Fernando | Sciencx | https://www.scien.cx/2023/03/24/paracetamol-js%f0%9f%92%8a-209-explica-este-codigo-javascript/ |
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.