Guest User

Untitled

a guest
Feb 21st, 2020
67
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let vasya = { name: "Вася", age: 25 };
  2. let petya = { name: "Петя", age: 15 };
  3. let masha = { name: "Маша", age: 28 };
  4.  
  5. let arrObj = [vasya, petya, masha];
  6.  
  7. function sortByName(mas) {
  8. mas.sort((a, b) => {
  9. if (a.name > b.name) {
  10. return 1;
  11. }
  12. if (a.name < b.name) {
  13. return -1;
  14. }
  15. return 0;
  16. });
  17.  
  18. }
  19.  
  20. function sortByAge(mas) {
  21. mas.sort((a, b) => a.age - b.age);
  22. }
  23.  
  24. console.log(arrObj[0].name, arrObj[1].name, arrObj[2].name);
  25. sortByName(arrObj);
  26. console.log(arrObj[0].name, arrObj[1].name, arrObj[2].name);
  27. sortByAge(arrObj);
  28. console.log(arrObj[0].name, arrObj[1].name, arrObj[2].name);
RAW Paste Data