Mode entretien. Minuteur de 5 min, sans indices ni autocomplétion
Sort by age
FacileFunctions5 min
Write a function sortByAge(users). It gets an array of users like { name, age } and sorts it by age, from the youngest to the oldest.
Sort the array itself and return it.
Exemples
sortByAge([{ name: 'Pete', age: 30 }, { name: 'John', age: 25 }, { name: 'Mary', age: 28 }])Renvoie [ { name: 'John', age: 25 }, { name: 'Mary', age: 28 }, { name: 'Pete', age: 30 } ]
Chargement de l'éditeur...
- Entrée
sortByAge([ { name: 'Pete', age: 30 }, { name: 'John', age: 25 }, { name: 'Mary', age: 28 } ])Attendu[ { name: 'John', age: 25 }, { name: 'Mary', age: 28 }, { name: 'Pete', age: 30 } ] - Sorts the array itself and returns it
Les tests cachés se lancent à la soumission