dabidabidesh

arguments problem

Feb 4th, 2021
372
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.  
  3.   let args = arguments;
  4.   let myObj = {};
  5.   //let result = [];
  6.  
  7.   function getTypeOfArgument(element) {
  8.     return typeof element;
  9.   }
  10.  
  11.   for (let i = 0; i < args.length; i++) {
  12.     const element = args[i];
  13.     const type = getTypeOfArgument(element);
  14.  
  15.     //if (type == `object`) {
  16.     //result.push(`${type}:`);
  17.     //} else {
  18.     console.log(`${type}: ${element}`);
  19.     //}
  20.  
  21.     if (myObj[type] == undefined) {
  22.       myObj[type] = [];
  23.     }
  24.     myObj[type].push(element);
  25.   }
  26.  
  27.   let sortable = [];
  28.  
  29.   for (let key in myObj) {
  30.     sortable.push([key, myObj[key].length]);
  31.   }
  32.  
  33.   sortable.sort((a, b) => b[1] - a[1]);
  34.  
  35.   for (let i = 0; i < sortable.length; i++) {
  36.     console.log(`${sortable[i][0]} = ${sortable[i][1]}`);
  37.   }
  38.  
  39.   //return result.join(`\n`);
  40. }
RAW Paste Data