Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

169
Visualizações
Getting specific value for every row from multiple rows

I have a code for fetching multiple selected rows. I can get all the rows of data but I am planning to get specific data that is merited. I'm stuck on getting the specific value of merits of each selected row and wanting to do code for their median. Please advise.

const median = {{ employeesTable.selectedRow.data }}
return median

Here is a sample data and what I'd like to get is only the merits which is 10 and 14 for example and get their median.

[{
   id:"15"
   email:"cornflakes123@gmail.com"
   employee_name:"Mark"
   merits:10
},
{
   id:"12"
   email:"fourleaves@gmail.com"
   employee_name:"Grey"
   merits:14
}]

My desired output to be showing is the median of the merit/s being selected. For example if three rows are selected, their merits are gathered and then given a median.

Example, if the three rows are having the merits of 5, 11 and 12 then the my desired output is to show the median 11 on ''return'' value.

almost 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

UPDATE 2

Getting the median with the following function (thanks goes to https://stackoverflow.com/a/53660837/8820118):

let data = [
      {
        id: "15",
        email: "cornflakes123@gmail.com",
        employee_name: "Mark",
        merits: 1,
      },
      {
        id: "12",
        email: "fourleaves@gmail.com",
        employee_name: "Grey",
        merits: 5,
      },
            {
        id: "12",
        email: "fourleaves@gmail.com",
        employee_name: "Grey",
        merits: 100,
      },
            {
        id: "12",
        email: "fourleaves@gmail.com",
        employee_name: "Grey",
        merits: 100,
      },
                  {
        id: "12",
        email: "fourleaves@gmail.com",
        employee_name: "Grey",
        merits: 500,
      },
    ]

function median(myData) {
    const sorted = Array.from(myData.map((item) => item.merits)).sort((a, b) => a - b);
    const middle = Math.floor(sorted.length / 2);

    if (sorted.length % 2 === 0) {
        return (sorted[middle - 1] + sorted[middle]) / 2;
    }

    return sorted[middle];
}

console.log(median(data));

UPDATE

Based on your comment you want to return the lowest merit value from your array.

const data = {{ employeesTable.selectedRow.data }}

//now that we have the data we can get min and max value
let min = Math.min(...data.map(item => item.merits));
let max = Math.max(...data.map(item => item.merits));

return min; //or return max

OLD POST

Just select the key from your object. Here is a little example based on your provided code:

const employeesTable = {
  selectedRow: {
    data: [
      {
        id: "15",
        email: "cornflakes123@gmail.com",
        employee_name: "Mark",
        merits: 10,
      },
      {
        id: "12",
        email: "fourleaves@gmail.com",
        employee_name: "Grey",
        merits: 14,
      },
    ],
  },
};

//iterate over the array
for (let i = 0; i < employeesTable.selectedRow.data.length; i++) {
  console.log(getMerits(i)); //return merit for that entry
}

function getMerits(index) {
  return employeesTable.selectedRow.data[index].merits;
}

Please give more details as your question can mean something else, for example only retrieving those with value 10 and 14. In that case provide more informations what you are trying to achieve.

almost 4 years ago · Santiago Trujillo Relatório

0

employeesTable.selectedRow.data.forEach((ele)=>{
  console.log(ele.id)
})
almost 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda