Pages

reduce

const posts = [
  {id: "moi", upVotes: 20},
  {id: "toi", upVotes: 89},
  {id: "lui", upVotes: 1},
  {id: "eux", upVotes: 123},];


let [premier,second] = posts.reduce((acc, cur) => [cur, ...acc].sort((a,b) => b.upVotes - a.upVotes).slice(0,2),[]);

console.log(`Au second tour sont présents : ${premier.id} et ${second.id}`);