Advertisement
Guest User

Easter Competition

a guest
Jun 15th, 2019
577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function competition(input) {
  2.     let numberOfCosunacks = Number(input.shift())
  3.  
  4.     let result = 0
  5.     let lowesResult = Number.MAX_SAFE_INTEGER
  6.     let biggestResult = Number.MIN_SAFE_INTEGER
  7.  
  8.     let realWinner = ""
  9.  
  10.     for (let index = 1; index <= numberOfCosunacks; index++) {
  11.         let nameOfBaker = input.shift()
  12.  
  13.         let command = input.shift()
  14.  
  15.         while (command != 'Stop') {
  16.             let gradeForAPerson = Number(command)
  17.  
  18.             result += gradeForAPerson
  19.  
  20.             command = input.shift()
  21.         }
  22.  
  23.         if (result > lowesResult) {
  24.             lowesResult = result
  25.         } else if (result > biggestResult) {
  26.             biggestResult = result
  27.             realWinner = nameOfBaker
  28.         }
  29.  
  30.         console.log(`${nameOfBaker} has ${result} points.`)
  31.  
  32.         if (index == 1) {
  33.             console.log(`${nameOfBaker} is the new number 1!`)
  34.         }
  35.  
  36.         if (biggestResult > lowesResult) {
  37.             console.log(`${nameOfBaker} is the new number 1!`)
  38.         }
  39.  
  40.         result = 0
  41.     }
  42.  
  43.     if (biggestResult) {
  44.        console.log(`${realWinner} won competition with ${biggestResult} points!`)
  45.     }
  46. }
  47.  
  48.  
  49. competition([3, 'Chef Manchev', 10, 10, 10, 10, 'Stop', 'Natalie', 8, 2, 9, 'Stop', 'George', 9, 2, 4, 2, 'Stop'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement