Last active
September 28, 2020 14:25
-
-
Save alisaliso/19564f8fa1fc9786716648fe7b72266a to your computer and use it in GitHub Desktop.
Issue #163 of rendezvous with cassidoo question
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
// 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 |
Isn't it
Math.ceil
instead offloor
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
Isn't it
Math.ceil
instead offloor
since if you need 17 slices and pizzas are sliced into 8, then you'll need 3, not 2? 🤔