ahribori / daily-algorithm

매일 알고리즘 문제풀자
1 stars 1 forks source link

Bon Appetit #19

Open ahribori opened 5 years ago

ahribori commented 5 years ago

https://www.hackerrank.com/challenges/bon-appetit/problem

ahribori commented 5 years ago
const bonAppetit = (bill, k, b) => {
  const totalPrice = bill.reduce((prev, next) => prev + next);
  const annaPrice = (totalPrice - bill[k]) / 2;
  const refund = b - annaPrice;
  return refund > 0 ? refund : 'Bon Appetit';
};

test('bonAppetit', () => {
  expect(bonAppetit([3, 10, 2, 9], 1, 12)).toBe(5);
  expect(bonAppetit([3, 10, 2, 9], 1, 7)).toBe('Bon Appetit');
});