File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * This class represents a regular pyramid and can calculate its volume and surface area
3+ * https://en.wikipedia.org/wiki/Pyramid_(geometry)
4+ * @constructor
5+ * @param {number } bsl - The side length of the base of the pyramid.
6+ * @param {number } height - The height of the pyramid
7+ */
8+ export default class Pyramid {
9+ constructor ( bsl , height ) {
10+ this . bsl = bsl
11+ this . height = height
12+ }
13+
14+ baseArea = ( ) => {
15+ return Math . pow ( this . bsl , 2 )
16+ }
17+
18+ volume = ( ) => {
19+ return this . baseArea ( ) * this . height / 3
20+ }
21+
22+ surfaceArea = ( ) => {
23+ return this . baseArea ( ) + this . bsl * 4 / 2 * Math . sqrt ( Math . pow ( this . bsl / 2 , 2 ) + Math . pow ( this . height , 2 ) )
24+ }
25+ }
Original file line number Diff line number Diff line change 1+ import Pyramid from '../Pyramid'
2+
3+ const pyramid = new Pyramid ( 3 , 5 )
4+
5+ test ( 'The Volume of a cone with base radius equal to 3 and height equal to 5' , ( ) => {
6+ expect ( parseFloat ( pyramid . volume ( ) . toFixed ( 2 ) ) ) . toEqual ( 15 )
7+ } )
8+
9+ test ( 'The Surface Area of a cone with base radius equal to 3 and height equal to 5' , ( ) => {
10+ expect ( parseFloat ( pyramid . surfaceArea ( ) . toFixed ( 2 ) ) ) . toEqual ( 40.32 )
11+ } )
You can’t perform that action at this time.
0 commit comments