function playGame(totalFunds, wagerAmount, totalBets, bet=1, funds=[]) {
const rollResultSuccess = flipUnfairCoin();
if (bet <= totalBets) {
if (rollResultSuccess) {
const newFunds = totalFunds + wagerAmount;
return playGame(
newFunds,
wagerAmount,
totalBets,
bet + 1,
R.append({bet, funds: newFunds}, funds),
);
}
const newFunds = totalFunds - wagerAmount;
return playGame(
newFunds,
wagerAmount,
totalBets,
bet + 1,
R.append({bet, funds: newFunds}, funds),
);
}
return funds;
}