Advertisement
GalinaKG

05. Inventory

Feb 23rd, 2023
773
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function inventory(array) {
  2.     let heroes = [];
  3.  
  4.     class Hero {
  5.         constructor(name,level,items){
  6.             this.name = name,
  7.             this.level = level,
  8.             this.items = items
  9.         }
  10.     }
  11.  
  12.     for(const data of array) {
  13.         let [name, level, items] = data.split(' / ');
  14.         let currentHero = new Hero(name,Number(level),items);
  15.         heroes.push(currentHero);
  16.     }
  17.  
  18.     heroes.sort((a, b) => {
  19.         return a.level - b.level
  20.     });
  21.  
  22.     for (const hero of heroes) {
  23.         console.log(`Hero: ${hero.name}\nlevel => ${hero.level}\nitems => ${hero.items}`)
  24.     }
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement