Skip to content

Instantly share code, notes, and snippets.

@Stefanacef
Last active October 13, 2021 11:11
Show Gist options
  • Save Stefanacef/7d991f68ac8f37bcc1d82b315afe6f1a to your computer and use it in GitHub Desktop.
Save Stefanacef/7d991f68ac8f37bcc1d82b315afe6f1a to your computer and use it in GitHub Desktop.
Solution for "Bill Division" in Hackerrank
const bill = [3, 10, 2, 9];
const k = 1;
const b = 12;
function bonAppetit(bill, k, b) {
const result = bill.reduce((acc, el) => acc + el, 0);
if((result-bill[k])/2===b)console.log('bun')
else{console.log(b-(result-bill[k])/2)}
///////////OR//////////////
if (k === 0) {
bill.shift();
} else {
bill.splice(k, 1);
}
const result = bill.reduce((acc, el) => acc + el / 2, 0);
if (result === b) {
console.log("Bon Appetit");
} else {
console.log(b - result);
}
}
bonAppetit(bill, k, b);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment