I'm diving into the world of nodejs and mongodb. Currently, I'm facing an issue with a JSON data structure that looks like this:
{
_id: 199,
name: 'Rae Kohout',
scores: [
{ type: 'exam', score: 82.11742562118049 },
{ type: 'quiz', score: 49.61295450928224 },
{ type: 'homework', score: 28.86823689842918 },
{ type: 'homework', score: 5.861613903793295 }
]
}
Specifically, I need to compare scores for the 'homework' type and remove the homework entry with the lowest score. In my attempt to tackle this problem, I've come up with the following code snippet:
var low = '';
for(var i=0;i<doc.scores.length;i++)
{
if(doc.scores[i].type == 'homework'){
if(low == ''){
low = doc.scores[i].score;
}
if( doc.scores[i].score > low ){
console.log("index for lowest score is " + i);
low = '';
}
}
}
At this point, I've successfully identified the index for the lowest score. However, I'm now struggling with removing values at that specific index as Array.splice() method only works on Arrays. Can someone provide guidance on how to solve this dilemma?