Skip to content

Instantly share code, notes, and snippets.

@Pandawan
Created December 9, 2021 19:13
Embed
What would you like to do?

This week’s question

You have to order wrapping paper for presents. Given the length, width, and height of the boxes you need to wrap, return the number of square feet (or whatever units you want) of wrapping paper you need to order. Extra credit: allow for other shapes of presents and their dimensions!

Example:

$ wrap(2, 3, 4)
52 square feet

My answer

Take the area of all sides:

function wrap(length, width, height) {
  const area = 2 * (length*width + length*height + width*height);
  return `${area} square feet`;
}

But arguably, when you wrap a present, you usually need more than the exact area—just so you can get nice folds and stuff. So I'd say you'd have to at least do 1.25x (if not 1.5x) that amount...

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