Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit014a38b

Browse files
authored
algorithm: volume of sphere (#1249)
* Added sphere volume* Fixed indentation* Added PR Suggestions
1 parentb634aa5 commit014a38b

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

‎Geometry/Sphere.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* This class represents a sphere and can calculate its volume and surface area
3+
*@constructor
4+
*@param {number} radius - The radius of the sphere
5+
*@see https://en.wikipedia.org/wiki/Sphere
6+
*/
7+
exportdefaultclassSphere{
8+
constructor(radius){
9+
this.radius=radius
10+
}
11+
12+
volume=()=>{
13+
returnMath.pow(this.radius,3)*Math.PI*4/3
14+
}
15+
16+
surfaceArea=()=>{
17+
returnMath.pow(this.radius,2)*Math.PI*4
18+
}
19+
}

‎Geometry/Test/Sphere.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
importSpherefrom'../Sphere'
2+
3+
constsphere=newSphere(3)
4+
5+
test('The Volume of a sphere with base radius equal to 3 and height equal to 5',()=>{
6+
expect(parseFloat(sphere.volume().toFixed(2))).toEqual(113.1)
7+
})
8+
9+
test('The Surface Area of a sphere with base radius equal to 3 and height equal to 5',()=>{
10+
expect(parseFloat(sphere.surfaceArea().toFixed(2))).toEqual(113.1)
11+
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp