Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function handle_company(args, cb) {
- const result = {};
- args.forEach(str => {
- const [key, value] = str.split(" -> ");
- if (!result[key]) {
- result[key] = [];
- }
- result[key].push(value);
- });
- cb(result);
- }
- handle_company(
- [
- "SoftUni -> AA12345",
- "SoftUni -> BB12345",
- "SoftUni -> AA12345",
- "Microsoft -> CC12345",
- "HP -> BB12345"
- ],
- result => {
- let keys = Object.keys(result).sort((a,b)=> a.localeCompare(b));
- for (const key of keys) {
- console.log(key);
- let filteredNum = result[key].filter((value,ind)=> result[key].indexOf(value) === ind)
- for (const value of filteredNum) {
- console.log("-- ", value);
- }
- }
- }
- )
Advertisement
Add Comment
Please, Sign In to add comment