Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

170
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

0

employeesTable.selectedRow.data.forEach((ele)=>{
  console.log(ele.id)
})
almost 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda