Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Recursive/Factorial.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @function Factorial
* @description function to find factorial using recursion.
* @param {Integer} n - The input integer
* @return {Integer} - Factorial of n.
* @see [Factorial](https://en.wikipedia.org/wiki/Factorial)
* @example 5! = 1*2*3*4*5 = 120
* @example 2! = 1*2 = 2
*/

const factorial = (n) => {
if (n === 0) {
return 1
}
return n * factorial(n - 1)
}

export { factorial }
11 changes: 0 additions & 11 deletions Recursive/factorial.js

This file was deleted.

11 changes: 11 additions & 0 deletions Recursive/test/Factorial.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { factorial } from '../Factorial'

describe('Factorial', () => {
it('should return factorial 1 for value "0"', () => {
expect(factorial(0)).toBe(1)
})

it('should return factorial 120 for value "5"', () => {
expect(factorial(5)).toBe(120)
})
})