Skip to content

Instantly share code, notes, and snippets.

@alisaliso
Last active September 28, 2020 14:25
Show Gist options
  • Save alisaliso/19564f8fa1fc9786716648fe7b72266a to your computer and use it in GitHub Desktop.
Save alisaliso/19564f8fa1fc9786716648fe7b72266a to your computer and use it in GitHub Desktop.
Issue #163 of rendezvous with cassidoo question
// 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.
const arr = [{ name: 'Joe', num: 9 }, { name: 'Cami', num: 3 }, { name: 'Cassidy', num: 4 }]
const gimmePizza = (arr, num) => {
const slices = arr.reduce((acc, person) => acc + person.num, 0);
return Math.ceil(slices / num);
}
gimmePizza(arr, 8);
$ 2 // 16 slices needed, pizzas can be sliced into 8 pieces, so 2 pizzas should be ordered
@lihbr
Copy link

lihbr commented Sep 28, 2020

Isn't it Math.ceil instead of floor since if you need 17 slices and pizzas are sliced into 8, then you'll need 3, not 2? 🤔

@alisaliso
Copy link
Author

Isn't it Math.ceil instead of floor since if you need 17 slices and pizzas are sliced into 8, then you'll need 3, not 2? 🤔

Yes, you right, it should be Math.ceil. Thank you! 🙃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment