mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-06 17:50:39 +08:00
algorithm: volume of sphere (#1249)
* Added sphere volume * Fixed indentation * Added PR Suggestions
This commit is contained in:
19
Geometry/Sphere.js
Normal file
19
Geometry/Sphere.js
Normal 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
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user