Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function competition(input) {
- let numberOfCosunacks = Number(input.shift())
- let result = 0
- let lowesResult = Number.MAX_SAFE_INTEGER
- let biggestResult = Number.MIN_SAFE_INTEGER
- let realWinner = ""
- for (let index = 1; index <= numberOfCosunacks; index++) {
- let nameOfBaker = input.shift()
- let command = input.shift()
- while (command != 'Stop') {
- let gradeForAPerson = Number(command)
- result += gradeForAPerson
- command = input.shift()
- }
- if (result > lowesResult) {
- lowesResult = result
- } else if (result > biggestResult) {
- biggestResult = result
- realWinner = nameOfBaker
- }
- console.log(`${nameOfBaker} has ${result} points.`)
- if (index == 1) {
- console.log(`${nameOfBaker} is the new number 1!`)
- }
- if (biggestResult > lowesResult) {
- console.log(`${nameOfBaker} is the new number 1!`)
- }
- result = 0
- }
- if (biggestResult) {
- console.log(`${realWinner} won competition with ${biggestResult} points!`)
- }
- }
- 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