Created
April 28, 2020 22:23
-
-
Save sandrabosk/f8de1b38d629b8fdfc3f9823362f8ff2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sort students by best score and list best 3 as fistPlace, secondPlace, thirdPlace. | |
// Add everyone else in the array. | |
const students = [ | |
{ | |
name: 'ana', | |
score: 5.4 | |
}, | |
{ | |
name: 'ivan', | |
score: 7.5 | |
}, | |
{ | |
name: 'milo', | |
score: 4.3 | |
}, | |
{ | |
name: 'igor', | |
score: 7.0 | |
}, | |
{ | |
name: 'george', | |
score: 8.9 | |
}, | |
{ | |
name: 'jess', | |
score: 10.0 | |
}, | |
{ | |
name: 'kevin', | |
score: 8.8 | |
}, | |
{ | |
name: 'beth', | |
score: 7.1 | |
} | |
]; | |
function sortByScore(arr) { | |
// .. your code here | |
} | |
sortByScore(students); | |
// { | |
// firstPlace: { name: 'jess', score: 10 }, | |
// secondPlace: { name: 'george', score: 8.9 }, | |
// thirdPlace: { name: 'kevin', score: 8.8 }, | |
// rest: [ | |
// { name: 'ivan', score: 7.5 }, | |
// { name: 'beth', score: 7.1 }, | |
// { name: 'igor', score: 7 }, | |
// { name: 'ana', score: 5.4 }, | |
// { name: 'milo', score: 4.3 } | |
// ] | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment