Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(arr) {
- let heroes = [];
- class Hero {
- constructor(name, level, items) {
- this.name = name;
- this.level = level;
- this.items = items;
- }
- }
- for (let info of arr) {
- info = info.split(' / ');
- const name = info[0];
- const level = Number(info[1]);
- const items = info[2].split(', ').sort((a, b) => a.localeCompare(b));
- heroes.push(new Hero(name, level, items));
- }
- for (const hero of heroes.sort((a, b) => (a.level - b.level))) {
- console.log(`Hero: ${hero.name}\nlevel => ${hero.level}`);
- if (hero.items) { console.log(`items => ${hero.items.join(', ')}`)}
- }
- }
Add Comment
Please, Sign In to add comment