JSFiddle - React, Tailwind, and code Playground
by nerdycap007
JavaScript
/*
n -> kids are sitting in a circle,
k -> toys available to distribute.
i -> position to start from.
Who (number of the kid) gets the last toy?
*/
function getKid(toys, kids, i) {
let val = (kids >= toys ? kids - toys + i : kids + i - 2)
return val > kids ? val - kids : val
}
console.log(getKid(3, 3, 1))