algorithm: volume of sphere (#1249)

* Added sphere volume

* Fixed indentation

* Added PR Suggestions
This commit is contained in:
Lcvieira2001
2022-10-31 13:39:41 -03:00
committed by GitHub
parent b634aa581c
commit 014a38b2d4
2 changed files with 30 additions and 0 deletions

19
Geometry/Sphere.js Normal file
View File

@ -0,0 +1,19 @@
/**
* This class represents a sphere and can calculate its volume and surface area
* @constructor
* @param {number} radius - The radius of the sphere
* @see https://en.wikipedia.org/wiki/Sphere
*/
export default class Sphere {
constructor (radius) {
this.radius = radius
}
volume = () => {
return Math.pow(this.radius, 3) * Math.PI * 4 / 3
}
surfaceArea = () => {
return Math.pow(this.radius, 2) * Math.PI * 4
}
}