0
I have the following objects below and need to verify which candidates meet the job requested.
var vaga = {"language":"javascript","courses":["information systems","programming"]}
var candidatos =
[
{"name":"luis","course":"programming","languages":["c","javascypt"]},{"name":"ana","course":"information systems","languages": "php","javascript","java"]},{"name":"pedro","course":"programming","languages":["javascript","java"]},{"name":"paulo","course":"programming","languages":["javascript","php","java"]},
{"name":"barbara","course":"information systems","languages":["php","javascript"]},
{"name":"camila","course":"programming","languages":["java","javascript"]},{"name":"cesar","course":"fashion","languages":["java","javascript","c"]},{"name":"cleber","course":"programming","languages":["reggae","javascript","dogs","football cards"]},{"name":"bruno","course":"programming","languages":["regex","javascript","perl","go","java"]},
{"name":"joana","course":"web design","languages":["java","javascript","c"]}
]
For this, I created the function below that returns an array with all candidates, however, I wanted to do this using filter()
, map()
and reduce()
, but I don’t know how.
function retornaCandidatos(vaga, candidatos) {
var x = [];
for (var i = 0; i < candidatos.length ; i++) {
for(var j = 0; j < vaga.courses.length; j++){
if(candidatos[i].course === oportunidade.courses[j]){
for(var k = 0; k < candidatos[i].languages.length; k++){
if(vaga.language === candidatos[i].languages[k]){
x.push(candidatos[i]);
}
}
}
}
}
return x;
}
Are you having a problem? This is Ecmascript. Some reason to change a routine that I believe is working well, you know and is efficient for another that you don’t know and is inefficient?
– Maniero
Where it comes from opportunity.?
– LeAndrade
@Maniero I think it should be for study reasons anyway, I think that for this *script * to be somewhat simple, maybe he has done an old course and wants to update himself.
– Eduardo Ribeiro
@Maniero, this was actually an exercise I needed to do, but I couldn’t use for, so I was looking for a way to do it using filter() or map().
– Luis
@Luis usually exercises that prohibit using
for
ask to use another flow control, that is, reduce abstraction and not increase. Did the exercise make this clear? If I didn’t, the exercise is flawed.– Maniero
@Maniero, didn’t make it clear, just said to use filter(), map() or reduce()
– Luis