I have the following objects and I need to check which candidates meet the requested job.
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 the candidates, but I wanted to do this using EcmaScript, but I'm not sure how I would do it using filter()
, map()
and reduce()
.
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;
}