Guest User

Untitled

a guest
Jun 4th, 2020
68
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     let index = 0;
  3.     let num = input[index];
  4.     index++;
  5.  
  6.     let redEggs = 0;
  7.     let orangeEggs = 0;
  8.     let blueEggs = 0;
  9.     let greenEggs = 0;
  10.  
  11.     for(let i = 1; i <= num; i++) {
  12.         let colour = input[index++];
  13.         switch(colour) {
  14.             case 'red': redEggs++; break;
  15.             case 'orange': orangeEggs++; break;
  16.             case 'blue': blueEggs++; break;
  17.             case 'green': greenEggs++; break;
  18.         }
  19.     }
  20.         let maxNumber = redEggs;
  21.         let maxColour = "red";
  22.         if(orangeEggs > maxNumber) {
  23.             maxColour = "orange";
  24.             maxNumber = orangeEggs
  25.         } if(blueEggs > maxNumber) {
  26.             maxColour = "blue";
  27.             maxNumber = blueEggs
  28.         } if(greenEggs > maxNumber) {
  29.             maxColour = "green";
  30.             maxNumber = greenEggs
  31.         }
  32.  
  33.       console.log(`Red eggs: ${redEggs}`);
  34.       console.log(`Orange eggs: ${orangeEggs}`);
  35.       console.log(`Blue eggs: ${blueEggs}`);
  36.       console.log(`Green eggs: ${greenEggs}`);
  37.       console.log(`Max eggs: ${maxNumber} -> ${maxColour}`);
  38. }
RAW Paste Data