Skip to content

Instantly share code, notes, and snippets.

@redrambles
Created June 5, 2023 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save redrambles/88f34cd173f80acdc370ae7acb203c34 to your computer and use it in GitHub Desktop.
Save redrambles/88f34cd173f80acdc370ae7acb203c34 to your computer and use it in GitHub Desktop.
const exampleArray = [
{ name: 'Joe', num: 9 },
{ name: 'Cami', num: 3 },
{ name: 'Cassidy', num: 4 }
];
const howManyPies = (arr, numSlicesPerPie) => {
const totalSlices = arr.reduce((acc, obj) => acc + obj.num, 0)
const numPies = Math.ceil(totalSlices / numSlicesPerPie)
return numPies
}
howManyPies(exampleArray, 3) // 6
howManyPies(exampleArray, 5) // 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment