Created
October 23, 2022 15:15
-
-
Save Scoty/e4b97bdf527d72420eccfc4fc9eafe6a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function bestPlayer(input) { | |
| let bestPlayerName = ""; | |
| let bestPlayerGoals = 0; | |
| let bestPlayerHetric = false; | |
| let inputLength = input.length | |
| let i = 0; | |
| while (true) { | |
| if (i > inputLength) { | |
| break; | |
| } | |
| let currrentEle = input[i]; | |
| let nextEle = input[i + 1] | |
| if (currrentEle === "END") { | |
| break; | |
| } | |
| if (bestPlayerGoals < nextEle) { | |
| bestPlayerName = currrentEle; | |
| bestPlayerGoals = nextEle; | |
| if (bestPlayerGoals >= 3) { | |
| bestPlayerHetric = true; | |
| } | |
| if (bestPlayerGoals >= 10) { | |
| break; | |
| } | |
| } | |
| i = i + 2; | |
| } | |
| // console.log(`${bestPlayerName} : ${bestPlayerGoals}`); | |
| console.log(`${bestPlayerName} is the best player!`); | |
| if (bestPlayerHetric) { | |
| console.log(`He has scored ${bestPlayerGoals} goals and made a hat-trick !!!`); | |
| } else { | |
| console.log(`He has scored ${bestPlayerGoals} goals.`); | |
| } | |
| } | |
| bestPlayer(["Neymar", | |
| "2", | |
| "Ronaldo", | |
| "1", | |
| "Messi", | |
| "3", | |
| "END"]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment