Ivankooo1

test

Mar 10th, 2020
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function handle_company(args, cb) {
  2.    const result = {};
  3.  
  4.    args.forEach(str => {
  5.      const [key, value] = str.split(" -> ");
  6.      if (!result[key]) {
  7.        result[key] = [];
  8.      }
  9.      result[key].push(value);
  10.    });
  11.    cb(result);
  12.  }
  13.  
  14.  handle_company(
  15.    [
  16.      "SoftUni -> AA12345",
  17.      "SoftUni -> BB12345",
  18.      "SoftUni -> AA12345",
  19.      "Microsoft -> CC12345",
  20.      "HP -> BB12345"
  21.    ],
  22.    result => {
  23.     let keys = Object.keys(result).sort((a,b)=> a.localeCompare(b));
  24.      for (const key of keys) {
  25.        console.log(key);
  26.        let filteredNum = result[key].filter((value,ind)=> result[key].indexOf(value) === ind)
  27.        for (const value of filteredNum) {
  28.          console.log("-- ", value);
  29.        }
  30.      }
  31.    }
  32.  )
Advertisement
Add Comment
Please, Sign In to add comment