Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. class Panstwo {
  2. constructor(nazwa, kontynent, populacja, powierzchnia) {
  3. this.nazwa = nazwa;
  4. this.kontynent = kontynent;
  5. this.populacja = populacja;
  6. this.powierzchnia = powierzchnia;
  7. }
  8. gestosc() {
  9. return this.populacja / this.powierzchnia;
  10. }
  11. }
  12. let polska = new Panstwo("Polska", "Europa", 38000000, 312000)
  13.  
  14. let tabp = [];
  15. tabp.push(polska)
  16. tabp.push(new Panstwo("Chiny", "Azja", 1420000000, 9500000))
  17. tabp.push(new Panstwo("Rosja", "Europa", 147000000, 17000000))
  18. tabp.push(new Panstwo("Indie", "Azja", 1296000000, 3290000))
  19.  
  20. // Sortowanie tabp
  21. function gestoscRosnaco(l, p) {
  22. return l.gestosc() - p.gestosc();
  23. }
  24. console.log(tabp.sort(gestoscRosnaco));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement