Advertisement
kstoyanov

01. Heroic Inventory

Sep 21st, 2020
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(arr) {
  2.   const heroes = [];
  3.  
  4.   arr.forEach((el) => {
  5.     const parts = el.split(/\s*\/\s*/);
  6.     const [name, level] = parts;
  7.  
  8.     let items = [];
  9.  
  10.     if (parts.length > 2) {
  11.       items = parts[2].split(', ');
  12.     }
  13.  
  14.     const hero = { name, level: Number(level), items };
  15.     heroes.push(hero);
  16.   });
  17.  
  18.  
  19.   console.log(JSON.stringify(heroes));
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement