Skip to content

Commit 92fb328

Browse files
committed
fit: check for negative numbers
1 parent e65c9a1 commit 92fb328

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

Recursive/Factorial.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ const factorial = (n) => {
1717
throw new RangeError('Not a Whole Number')
1818
}
1919

20+
if (n < 0) {
21+
return undefined
22+
}
23+
2024
if (n === 0) {
2125
return 1
2226
}

Recursive/test/Factorial.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,9 @@ describe('Factorial', () => {
1515
expect(() => factorial(undefined)).toThrow('Not a Number')
1616
expect(() => factorial(3.142)).toThrow('Not a Whole Number')
1717
})
18+
19+
it('Should return undefined for value less than 0', () => {
20+
expect(factorial(-1)).toBe(undefined)
21+
expect(factorial(-100)).toBe(undefined)
22+
})
1823
})

0 commit comments

Comments
 (0)