Last active
July 2, 2019 14:21
-
-
Save wongjiahau/dc7b35e7536d0a46b3d476518c5165c8 to your computer and use it in GitHub Desktop.
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
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