Todorov_Stanimir

04. Party Time Associative Arrays - Exercise

May 24th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function partyTime(input) {
  2.  
  3.     let output = new Map();
  4.     output.set("VIP", []);
  5.     output.set("regular", [])
  6.     let gestComming = false;
  7.  
  8.     for (let currentOperation of input) {
  9.         if (currentOperation === 'PARTY') {
  10.             gestComming = true;
  11.         } else {
  12.             if (gestComming === false) {
  13.                 if (48 <= currentOperation.charCodeAt(0) && currentOperation.charCodeAt(0) <= 57) {
  14.                     output.get('VIP').push(currentOperation);
  15.                 } else {
  16.                     output.get('regular').push(currentOperation);
  17.                 }
  18.             } else {
  19.                 if (48 <= currentOperation.charCodeAt(0) && currentOperation.charCodeAt(0) <= 57) {
  20.                     output.get('VIP').splice(output.get('VIP').indexOf(currentOperation), 1);
  21.                 } else {
  22.                     output.get('regular').splice(output.get('regular').indexOf(currentOperation), 1);
  23.                 }
  24.             }
  25.         }
  26.     }
  27.     let sorted=output.get('VIP').concat(output.get('regular'));
  28.  
  29.     console.log(sorted.length);
  30.     for (let guest of sorted){
  31.         console.log(guest);
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment