Last active
July 25, 2017 02:43
-
-
Save NickFoden/d9be48be46eef6d77a597f8062c5a5bd to your computer and use it in GitHub Desktop.
Clerk Challenge
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
let peopleInLine = []; | |
function tickets(peopleInLine) { | |
let ticket25 = 0; | |
let ticket50 = 0; | |
let ticket100 = 0; | |
for (i = 0; i < peopleInLine.length; i++) { | |
if (peopleInLine[i] === 100) { | |
if (ticket50 >= 1 && ticket25 >= 1) { | |
ticket50 -= 1; | |
ticket25 -= 1; | |
ticket100++; | |
} | |
else if (ticket25 >= 3) { | |
ticket25 -= 3; | |
ticket100++; | |
}else{ | |
return "NO"; | |
} | |
}else if (peopleInLine[i] === 50) { | |
if (ticket25 >= 1) { | |
ticket25 -= 1; | |
ticket50 += 1; | |
}else{ | |
return "NO"; | |
} | |
}else if (peopleInLine[i] === 25) { | |
ticket25++; | |
} | |
} | |
return "YES"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment