Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Panstwo {
- constructor(nazwa, kontynent, populacja, powierzchnia) {
- this.nazwa = nazwa;
- this.kontynent = kontynent;
- this.populacja = populacja;
- this.powierzchnia = powierzchnia;
- }
- gestosc() {
- return this.populacja / this.powierzchnia;
- }
- }
- let polska = new Panstwo("Polska", "Europa", 38000000, 312000)
- let tabp = [];
- tabp.push(polska)
- tabp.push(new Panstwo("Chiny", "Azja", 1420000000, 9500000))
- tabp.push(new Panstwo("Rosja", "Europa", 147000000, 17000000))
- tabp.push(new Panstwo("Indie", "Azja", 1296000000, 3290000))
- // Sortowanie tabp
- function gestoscRosnaco(l, p) {
- return l.gestosc() - p.gestosc();
- }
- console.log(tabp.sort(gestoscRosnaco));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement