Operation between models

5

I do not know the power of javascript very well, but wanted to do the following:

I have two models:

Vacancy:

{
    Name: "VagaExemplo",
    Description: "Descricao",
    Skills: {
        "56b68108869038280db291e6": "90",
        "56b68108869038280db291d9": "70",
    }
}

and various templates of the type:

Person1

{
    Name: "PessoaExemplo",
    Description: "Descricao",
    Skills: {
        "56b68108869038280db291d9": "60",
    },
    Pontuacao: 10
}

Person2

{
    Name: "PessoaExemplo2",
    Description: "Descricao",
    Skills: {
        "56b68108869038280db291e6": "90",
        "56b68108869038280db291d9": "80",
    },
    Pontuacao: 0
}

The idea is to multiply the value of each skill of the job with that of the person and add up to generate a score for the person.

Could anyone help me or at least a link to a material about it? Hugs.

    
asked by anonymous 09.02.2016 / 20:47

1 answer

3

I think what you are looking for is this:

var pontos = pessoas.map(function(pessoa) {
    var pontos = 0;
    Object.keys(pessoa.Skills).forEach(function(codigo) {
        pontos += parseInt(tabela.Skills[codigo], 10) * parseInt(pessoa.Skills[codigo], 10);
    });
    return pontos;
});

Starting from the principle that each person is an object, within an array.

Example: link

If you also want to have the person's name in the final result you can do this: link

What this code does is know how many Skills one has with Object.keys(pessoa.Skills) . Then for each code of this skill goes to the table to get the multiplier. Use parseInt because these numbers are like String , if they were numbers it would not be accurate.

    
09.02.2016 / 21:29