Files
freeCodeCamp/curriculum/challenges/english/blocks/daily-coding-challenges-javascript/69f8c998d78ad3171a0713bd.md
T

1.6 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
69f8c998d78ad3171a0713bd Challenge 290: Pizza Party 28 challenge-290

--description--

Given an array of hours worked today per person, return the number of pizzas to order for a pizza party.

  • Divide each person's hours worked by 3 to get their slice count.
  • You can't eat a partial slice, so round each person's slice count up to the nearest whole number.
  • Each person gets a minimum of two slices.
  • Each pizza has 8 slices. Round the total number of pizzas up to the nearest whole pizza.

--hints--

getPizzasToOrder([8, 8, 8]) should return 2.

assert.equal(getPizzasToOrder([8, 8, 8]), 2);

getPizzasToOrder([10, 9, 8, 2, 2, 6, 10]) should return 3.

assert.equal(getPizzasToOrder([10, 9, 8, 2, 2, 6, 10]), 3);

getPizzasToOrder([1, 2, 3, 4, 5]) should return 2.

assert.equal(getPizzasToOrder([1, 2, 3, 4, 5]), 2);

getPizzasToOrder([8, 8, 8, 8, 8, 8, 8, 8]) should return 3.

assert.equal(getPizzasToOrder([8, 8, 8, 8, 8, 8, 8, 8]), 3);

getPizzasToOrder([9, 9, 6]) should return 1.

assert.equal(getPizzasToOrder([9, 9, 6]), 1);

getPizzasToOrder([10, 12, 16, 9, 8, 11, 15, 8, 0]) should return 5.

assert.equal(getPizzasToOrder([10, 12, 16, 9, 8, 11, 15, 8, 0]), 5);

--seed--

--seed-contents--

function getPizzasToOrder(hoursWorked) {

  return hoursWorked;
}

--solutions--

function getPizzasToOrder(hoursWorked) {
  const totalSlices = hoursWorked.reduce((sum, hours) => {
    return sum + Math.max(Math.ceil(hours / 3), 2);
  }, 0);

  return Math.ceil(totalSlices / 8);
}