Skip to content

Instantly share code, notes, and snippets.

@wptechprodigy
Last active April 29, 2020 15:57
Show Gist options
  • Save wptechprodigy/10cda2e93dcce5142d33e6747ae564aa to your computer and use it in GitHub Desktop.
Save wptechprodigy/10cda2e93dcce5142d33e6747ae564aa to your computer and use it in GitHub Desktop.
Health Status Test Solution
/**
* 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