Advertisement
kstoyanov

02. Argument Info

Oct 9th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function printInfo(...input) {
  2.   function printSortedObject() {
  3.     Object.entries(obj)
  4.       .sort((a, b) => b[1] - a[1])
  5.       .forEach((el) => output.push(`${el[0]} = ${el[1]}`));
  6.   }
  7.  
  8.   function createObject() {
  9.     input.forEach((el) => {
  10.       let type;
  11.  
  12.       if (typeof el === 'object' && Object.values(el).length) {
  13.         type = typeof el;
  14.         output.push(`${type}:`);
  15.  
  16.         Object.values(el).forEach((e) => {
  17.           fillObjectData(typeof e);
  18.         });
  19.       } else {
  20.         type = typeof el;
  21.         output.push(`${type}: ${el}`);
  22.         fillObjectData(type);
  23.       }
  24.     });
  25.   }
  26.  
  27.   function fillObjectData(type) {
  28.     if (!obj[type]) {
  29.       obj[type] = 0;
  30.     }
  31.     obj[type]++;
  32.   }
  33.  
  34.   const obj = {};
  35.   const output = [];
  36.  
  37.   createObject();
  38.   printSortedObject();
  39.  
  40.   output.forEach((e) => console.log(e));
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement