Created
July 10, 2017 00:08
-
-
Save leandroCodeDev/b1f8563f1df4359c92a2c2c9162951e8 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 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