Skip to content

Instantly share code, notes, and snippets.

@leandroCodeDev
Created July 10, 2017 00:08
Show Gist options
  • Save leandroCodeDev/b1f8563f1df4359c92a2c2c9162951e8 to your computer and use it in GitHub Desktop.
Save leandroCodeDev/b1f8563f1df4359c92a2c2c9162951e8 to your computer and use it in GitHub Desktop.
problema em utilizar o if com catsh
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 valor = pesquisa
resposta = _.find(games, (jogo_atual)=>{
return resultado = jogo_atual.name == valor
})
if (resposta == ''){
rejeita = 'objeto nao encontrado'
}else{
resolve(resposta)}}
,5*1000);
});
}
console.log('Carregando ....')
var resposta = 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