Generation

generate functionTue, 28 Mar 2023

Mostrar todos los contactos ordenados por su edad.

Script var friends = [{ name: 'John', age: 30 }, { name: 'Ana', age: 20 }, { name: 'Chris', age: 25 }]; function printSorted(friends) { friends.sort(function (a, b) { return a.age - b.age; }); for (var i = 0; i < friends.length; i++) { console.log(friends[i].name); } } printSorted(friends);

Want to kickstart your project?Use the new AI Studio to create your code