Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function easterEggs(input) {
- let quantity = Number(input[0]);
- let red = 0;
- let orange = 0;
- let blue = 0;
- let green = 0;
- let maxCount = 0;
- let maxColor = "";
- for (let i = 1; i <= quantity; i++) {
- let color = input[i];
- switch (color) {
- case "red":
- red++;
- break;
- case "orange":
- orange++;
- break;
- case "blue":
- blue++;
- break;
- case "green":
- green++;
- break;
- }
- }
- if (red > orange && red > blue && red > green) {
- maxCount = red;
- maxColor = "red";
- } else if (orange > blue && orange > green && orange > red) {
- maxCount = orange;
- maxColor = "orange";
- } else if (blue > green && blue > red && blue > orange) {
- maxCount = blue;
- maxColor = "blue";
- } else {
- maxCount = green;
- maxColor = "green";
- }
- console.log(`Red eggs: ${red}`);
- console.log(`Orange eggs: ${orange}`);
- console.log(`Blue eggs: ${blue}`);
- console.log(`Green eggs: ${green}`);
- console.log(`Max eggs: ${maxCount} -> ${maxColor}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement