GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — algorithm: volume of sphere (#1249) · TheAlgorithms/JavaScript@014a38b

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Geometry
    • Sphere.js
    • Test
      • Sphere.test.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Geometry/Sphere.js‎

Copy file name to clipboard
+19Lines 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+
export default class Sphere {
8+
constructor (radius) {
9+
this.radius = radius
10+
}
11+
12+
volume = () => {
13+
return Math.pow(this.radius, 3) * Math.PI * 4 / 3
14+
}
15+
16+
surfaceArea = () => {
17+
return Math.pow(this.radius, 2) * Math.PI * 4
18+
}
19+
}
Collapse file

‎Geometry/Test/Sphere.test.js‎

Copy file name to clipboard
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Sphere from '../Sphere'
2+
3+
const sphere = new Sphere(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 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.