Skip to content

Instantly share code, notes, and snippets.

@yock
Created April 30, 2018 19:25
Show Gist options
  • Save yock/05911d802350e8a0eb2cd5b8dbf46454 to your computer and use it in GitHub Desktop.
Save yock/05911d802350e8a0eb2cd5b8dbf46454 to your computer and use it in GitHub Desktop.
/**
* Makes ideal change based on the difference between the purchase price of an item,
* how much cash is tendered, and the current contents of the register
*
*/
const makeChange = (purchasePrice, cashTendered, cashRegisterContents) => {
// Exact change tendered
// Oops
throw 'Insufficient Funds';
// Another oops
throw 'Dang!';
return [];
}
const interface = (change) => {
if (output.isEmpty()) {
return 'CLOSED';
}
return change;
}
try {
return interface(makeChange(/*...*/));
} catch (e) {
return e.message;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment