Last active
April 29, 2020 15:57
-
-
Save wptechprodigy/10cda2e93dcce5142d33e6747ae564aa to your computer and use it in GitHub Desktop.
Health Status Test Solution
This file contains 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
/** | |
* Gets the seat number of the develper to get the last sweet | |
* of some sweets distributed as a treat to developers. The last sweet | |
* happens to taste AWFUL. | |
* | |
* @param n Number of developers | |
* @param m Number of sweets | |
* @param s Chair number to begin passing out sweets | |
* | |
* @returns Seat number of the developer to be warned | |
*/ | |
function warnTheDeveloper(n, m, s) { | |
if (typeof n !== 'number' || typeof m !== 'number' || typeof s !== 'number') { | |
// Assuming we can't have neither of developers, sweets nor chair numbers to be zero | |
if (n < 1 || m < 1 || s < 1) return 'Number has to be greater than 1'; | |
return 'Provide a valid number'; | |
} | |
let developerSeatNumber; | |
const sweetsLeftAfterPossiblyGoingRound = m % n; | |
// Starting from the first person while sweets can go round | |
if (sweetsLeftAfterPossiblyGoingRound === 0 && s === 1) { | |
return n; | |
} | |
developerSeatNumber = s + sweetsLeftAfterPossiblyGoingRound - 1; | |
return developerSeatNumber; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment