Passed "factorial" using recursive function in exercise 08
This commit is contained in:
		
							parent
							
								
									72da0d32bc
								
							
						
					
					
						commit
						afbd11dad1
					
				|  | @ -24,8 +24,11 @@ const power = function(a, x) { | ||||||
| 	return 4 ** 3; | 	return 4 ** 3; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| const factorial = function() { | const factorial = function(a) { | ||||||
| 	 | 	if (a <= 1) { | ||||||
|  |     return 1; | ||||||
|  |   } | ||||||
|  |   return a * factorial(a - 1); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| // Do not edit below this line
 | // Do not edit below this line
 | ||||||
|  |  | ||||||
|  | @ -55,23 +55,23 @@ describe('power', () => { | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| describe('factorial', () => { | describe('factorial', () => { | ||||||
|   test.skip('computes the factorial of 0', () => { |   test('computes the factorial of 0', () => { | ||||||
|     expect(calculator.factorial(0)).toBe(1); // 0! = 1
 |     expect(calculator.factorial(0)).toBe(1); // 0! = 1
 | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|   test.skip('computes the factorial of 1', () => { |   test('computes the factorial of 1', () => { | ||||||
|     expect(calculator.factorial(1)).toBe(1); |     expect(calculator.factorial(1)).toBe(1); | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|   test.skip('computes the factorial of 2', () => { |   test('computes the factorial of 2', () => { | ||||||
|     expect(calculator.factorial(2)).toBe(2); |     expect(calculator.factorial(2)).toBe(2); | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|   test.skip('computes the factorial of 5', () => { |   test('computes the factorial of 5', () => { | ||||||
|     expect(calculator.factorial(5)).toBe(120); |     expect(calculator.factorial(5)).toBe(120); | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|   test.skip('computes the factorial of 10', () => { |   test('computes the factorial of 10', () => { | ||||||
|     expect(calculator.factorial(10)).toBe(3628800); |     expect(calculator.factorial(10)).toBe(3628800); | ||||||
|   }); |   }); | ||||||
| }); | }); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue