Last active
October 13, 2021 11:11
-
-
Save Stefanacef/7d991f68ac8f37bcc1d82b315afe6f1a to your computer and use it in GitHub Desktop.
Solution for "Bill Division" in Hackerrank
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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