Skip to content

Instantly share code, notes, and snippets.

@Scoty
Created October 23, 2022 15:15
Show Gist options
  • Save Scoty/e4b97bdf527d72420eccfc4fc9eafe6a to your computer and use it in GitHub Desktop.
Save Scoty/e4b97bdf527d72420eccfc4fc9eafe6a to your computer and use it in GitHub Desktop.
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