Forked from leandroCodeDev/gist:b1f8563f1df4359c92a2c2c9162951e8
Last active
July 10, 2017 01:05
-
-
Save stewones/c806cce30349001926d0cfa6087a3a96 to your computer and use it in GitHub Desktop.
problema em utilizar o if com catsh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let _ = require('lodash'); | |
let games = [ | |
{ | |
name: 'Street Fighter', | |
year: 1990 | |
}, | |
{ | |
name: 'Mortal Kombat' , | |
year: 1991 | |
}, | |
{ | |
name: 'Top Gear' , | |
year: 1992 | |
} | |
] | |
function busca(pesquisa){ | |
return new Promise((resolve, rejeita) =>{ | |
setTimeout( ()=>{ | |
let resposta = _.find(games, (jogo_atual)=>{ | |
return jogo_atual.name == pesquisa | |
}) | |
if (!resposta){ | |
rejeita('objeto nao encontrado'); | |
}else{ | |
resolve(resposta)}} | |
,5*1000); | |
}); | |
} | |
console.log('Carregando ....') | |
busca('Top Gar').then( (resposta)=>console.log('o jogo encontrado foi: ',resposta)) | |
.catch((e)=>{ | |
console.log('objeto nao encontrado') | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment