Skip to content

Instantly share code, notes, and snippets.

@benschac
Created September 28, 2020 15:22
Show Gist options
  • Save benschac/8a7065708566ebdd80e3bae82cd9c4da to your computer and use it in GitHub Desktop.
Save benschac/8a7065708566ebdd80e3bae82cd9c4da to your computer and use it in GitHub Desktop.
// Given an array of people objects (where each person has a name and a number of pizza slices they’re hungry for)
// and a number for the number of slices that the pizza can be sliced into, return the number of pizzas you need to buy.
function gimmePizza(arr, slices) {
let totalSlices = arr.reduce((prev, curr) => {
prev += curr.num;
return prev;
}, 0);
return Math.ceil(totalSlices / slices);
}
let people = [
{ name: "Joe", num: 9 },
{ name: "Cami", num: 3 },
{ name: "Cassidy", num: 4 },
];
console.log(gimmePizza(people, 8));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment