Skip to content

Instantly share code, notes, and snippets.

@wongjiahau
Last active July 2, 2019 14:21
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 wongjiahau/dc7b35e7536d0a46b3d476518c5165c8 to your computer and use it in GitHub Desktop.
Save wongjiahau/dc7b35e7536d0a46b3d476518c5165c8 to your computer and use it in GitHub Desktop.
const getArea = (shape: Shape) => {
if (shape.radius) {
return Math.PI * Math.pow(shape.radius, 2)
}
else if (shape.height && shape.width) {
return shape.height * shape.width
}
else if (shape.base && shape.height) {
return 0.5 * shape.base * shape.height
}
else {
throw new Error('Invalid shape')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment