Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function bestPlayer(input) {
- let index = 0
- let playerName = input[index];
- index++;
- let score = input[index];
- let maxGoals = Number.MIN_SAFE_INTEGER
- let bestPlayer = ""
- while (playerName !== "END") {
- score = Number(input[index]);
- if (score > maxGoals) {
- maxGoals = score
- if (playerName !== "END") {
- bestPlayer = playerName
- } else {
- break;
- }
- if (score >= 10) {
- console.log(`${bestPlayer} is the best player`);
- console.log(`He has scored ${maxGoals} goals and made a hat-trick`);
- return;
- }
- } else {
- index++;
- playerName = input[index];
- index++;
- }
- }
- if (maxGoals >= 3) {
- console.log(`${bestPlayer} is the best player`);
- console.log(`He has scored ${maxGoals} goals and made a hat-trick`);
- } else if (maxGoals < 3) {
- console.log(`He has scored ${maxGoals} goals `);
- }
- }
- bestPlayer(["Neymar", "2", "Ronaldo", "1", "Messi", "3", "END"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement