Files
JavaScript/Geometry/Sphere.js
Lcvieira2001 014a38b2d4 algorithm: volume of sphere (#1249)
* Added sphere volume

* Fixed indentation

* Added PR Suggestions
2022-10-31 22:09:41 +05:30

20 lines
445 B
JavaScript

/**
* 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
}
}