Pick the top two
Take your time, follow the code and check your understanding.
The codeRAG fundamentals
const scores = [
{ id: "a", s: 0.31 }, { id: "b", s: 0.82 },
{ id: "c", s: 0.55 }, { id: "d", s: 0.82 }
];
const top = [...scores].sort((x, y) => y.s - x.s).slice(0, 2).map(x => x.id);
console.log(top.join(","));Your answer4 min · no timer
Show solution and explanation
Sorting is descending by score. Array.sort is stable in modern JavaScript, so b and d keep their original order when scores tie. The first two are b and d.
b,d