Modo entrevista. Cronômetro de 5 min, sem dicas e sem autocompletar
Sort by age
FácilFunctions5 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.
Exemplos
sortByAge([{ name: 'Pete', age: 30 }, { name: 'John', age: 25 }, { name: 'Mary', age: 28 }])Retorna [ { name: 'John', age: 25 }, { name: 'Mary', age: 28 }, { name: 'Pete', age: 30 } ]
Carregando o editor...
- Entrada
sortByAge([ { name: 'Pete', age: 30 }, { name: 'John', age: 25 }, { name: 'Mary', age: 28 } ])Esperado[ { name: 'John', age: 25 }, { name: 'Mary', age: 28 }, { name: 'Pete', age: 30 } ] - Sorts the array itself and returns it
Os testes ocultos rodam no envio