hi guys i have a problem here, i want to get the lowest three values from the array of javascript objects. and the array of object is like this
let array = [{student_id: 'asda123asd1', nrw: 70}, {student_id: 'asda123asd2', nrw: 80}, {student_id: 'asda123asd3', nrw: 50}, {student_id: 'asda123asd4', nrw: 50}, {student_id: 'asda123asd5', nrw: 100}];
the result i want is like this
[{student_id: 'asda123asd3', nrw: 50}, {student_id: 'asda123asd4', nrw: 50},{student_id: 'asda123asd1', nrw: 70}]
i have tried this but didnt solve my problem
let test = async (array, n) => {
let empty = []
let MAX = 100000;
let firstmin = MAX;
let secmin = MAX;
let thirdmin = MAX;
for (let i = 0; i < n;i++)
{
/* Check if current element is less than
firstmin, then update first, second and
third */
if (array[i].nrw < firstmin)
{
thirdmin = secmin;
secmin = firstmin;
firstmin = array[i].nrw;
}
/* Check if current element is less than
secmin then update second and third */
else if (array[i].nrw < secmin)
{
thirdmin = secmin;
secmin = array[i].nrw;
}
/* Check if current element is less than
then update third */
else if (array[i].nrw < thirdmin)
thirdmin = array[i].nrw;
}
if(firstmin != 100000){
empty.push({nrw: firstmin})
}
if(secmin != 100000){
empty.push({nrw: secmin})
}
if(thirdmin != 100000){
empty.push({nrw: thirdmin})
}
console.log(empty)
}
how can you guys solve this?