Advertisement
Spocoman

Easter Eggs

Feb 21st, 2022 (edited)
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function easterEggs(input) {
  2.     let quantity = Number(input[0]);
  3.     let red = 0;
  4.     let orange = 0;
  5.     let blue = 0;
  6.     let green = 0;
  7.     let maxCount = 0;
  8.     let maxColor = "";
  9.  
  10.     for (let i = 1; i <= quantity; i++) {
  11.         let color = input[i];
  12.         switch (color) {
  13.             case "red":
  14.                 red++;
  15.                 break;
  16.             case "orange":
  17.                 orange++;
  18.                 break;
  19.             case "blue":
  20.                 blue++;
  21.                 break;
  22.             case "green":
  23.                 green++;
  24.                 break;
  25.         }
  26.     }
  27.  
  28.     if (red > orange && red > blue && red > green) {
  29.         maxCount = red;
  30.         maxColor = "red";
  31.     } else if (orange > blue && orange > green && orange > red) {
  32.         maxCount = orange;
  33.         maxColor = "orange";
  34.     } else if (blue > green && blue > red && blue > orange) {
  35.         maxCount = blue;
  36.         maxColor = "blue";
  37.     } else {
  38.         maxCount = green;
  39.         maxColor = "green";
  40.     }
  41.  
  42.     console.log(`Red eggs: ${red}`);
  43.     console.log(`Orange eggs: ${orange}`);
  44.     console.log(`Blue eggs: ${blue}`);
  45.     console.log(`Green eggs: ${green}`);
  46.     console.log(`Max eggs: ${maxCount} -> ${maxColor}`);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement