// This is cleaner, but could run into recursion limits // Note that this does not handle the removal of the original 50 seats assigned to each state. // An update is in https://stackoverflow.com/a/70560879/1243641 const apportion = ( total, pops, seats = Object.fromEntries (Object.entries(pops).map(([s, _]) => [s, 1])), state = nextSeat (seats, pops) ) => total <= 0 ? seats : apportion (total - 1, pops, {...seats, [state]: seats[state] + 1})