Advertisement
nikolayneykov

Untitled

Mar 18th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     let output = [];
  3.  
  4.     for (element of input) {
  5.         let name = element.split(`,`)[0];
  6.         if (!output.includes(element)) {
  7.             output.push(name);
  8.         }
  9.         output
  10.             .sort((a, b) => {
  11.                 let result =a.length - b.length;
  12.  
  13.                 if (result === 0) {
  14.                     result = a.localeCompare(b);
  15.                 }
  16.  
  17.                 return result;
  18.             });
  19.     }
  20.     console.log(output.join(`\n`));
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement