Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function inventory(arr){
- const heroes = [];
- for(let element of arr){
- element = element.split(' / ');
- let heroName = element.shift();
- let level = element.shift();
- let items = element.join('').split(', ').sort();
- const hero = {
- name : heroName,
- level : Number(level),
- items : items
- }
- heroes.push(hero);
- }
- const heroesAscending = [];
- heroesAscending.push(heroes.shift());
- for(let hero of heroes){
- let level = hero.level;
- if(level < heroesAscending[0].level){
- heroesAscending.unshift(hero);
- }else if(level > heroesAscending[heroesAscending.length - 1].level){
- heroesAscending.push(hero);
- }
- }
- for(let hero of heroesAscending){
- console.log(`Hero: ${hero.name}\nlevel => ${hero.level}\nitems => ${hero.items.join(', ')}`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement