Created
October 2, 2022 01:07
-
-
Save Nasah-Kuma/0c7ba9912b6c81cc4c670a6b6a98b710 to your computer and use it in GitHub Desktop.
Solution to HackerRank Challenge: https://www.hackerrank.com/challenges/bon-appetit/problem?isFullScreen=true
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
/* | |
* Complete the 'bonAppetit' function below. | |
* | |
* The function accepts following parameters: | |
* 1. INTEGER_ARRAY bill | |
* 2. INTEGER k | |
* 3. INTEGER b | |
*/ | |
function bonAppetit(bill, k, b) { | |
let actualBill = 0; | |
let totalCost = 0; | |
for (let item of bill) totalCost+=item; | |
actualBill = (totalCost - bill[k])/2; | |
console.log(actualBill === b ? 'Bon Appetit' : b - actualBill); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment