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

Commit b83abac

Browse files
Merge pull request knaxus#94 from iamvalentin23/master
Added factorial problem and solution
2 parents 1387eef + 8b6edf9 commit b83abac

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

‎src/_Problems_/factorial/index.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function factorial(num) {
2+
if (num === 1) return num;
3+
else return num * factorial(num - 1);
4+
}
5+
6+
module.exports = {
7+
factorial,
8+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const { factorial } = require('.');
2+
3+
describe('Factorial', () => {
4+
it('Should return 24', () => {
5+
expect(factorial(4)).toEqual(24);
6+
});
7+
8+
it('Should return 1', () => {
9+
expect(factorial(1)).toEqual(1);
10+
});
11+
12+
it('Should return 120', () => {
13+
expect(factorial(5)).toEqual(120);
14+
});
15+
});

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /