-
Notifications
You must be signed in to change notification settings - Fork 41.2k
feat(factorial): create exercise #441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nik-rev
wants to merge
18
commits into
TheOdinProject:main
Choose a base branch
from
nik-contrib:feat/exercise_13
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 15 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
ed7975a
feat| create spec files
nik-rev 8845572
feat| create readme
nik-rev 670d85e
feat| create solution files
nik-rev 4d46031
fix| factorial solution now passes
nik-rev ee05ca9
feat| spec file fixed
nik-rev f317492
fix| spec
nik-rev 3530f26
feat/ add comments
nik-rev 6c72df8
fix/ refactor
nik-rev dc40770
feat/ improve wording
nik-rev 882d418
feat/ update function to not accept strings
nik-rev 052637d
feat/ remove comment
nik-rev eaabc5b
feat/ improve order
nik-rev 3bc0482
feat/ remove unnecesary describe
nik-rev ab1e728
feat/ single quotes replaced with double quotes
nik-rev f1f29ac
feat/ add wikipedia link to factorial
nik-rev 54dd2ce
Update 13_factorial/README.md
nik-rev 8b2ed42
Update 13_factorial/factorial.spec.js
nik-rev 10d559d
feat(factorial): remove .skip from all tests under solution
nik-rev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Exercise 13 - Factorial | ||
|
||
Write a [recursive factorial function](https://simple.wikipedia.org/wiki/Factorial) that takes a non-negative integer, and returns the product of all positive integers less than or equal to the input integer. An input of `0` should return `1`. The function should only accept numbers, so `'4'` should not be accepted as it is a string. All invalid inputs should return `undefined`. | ||
|
||
For example: | ||
|
||
```javascript | ||
factorial(5); // 5 * 4 * 3 * 2 * 1, Output: 120 | ||
factorial(0); // Output: 1 | ||
factorial(7.2); // Output: undefined | ||
factorial('4'); // Output: undefined | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const factorial = function() { | ||
|
||
}; | ||
|
||
// Do not edit below this line | ||
module.exports = factorial; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const factorial = require("./factorial-solution"); | ||
nik-rev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
describe('factorial', () => { | ||
test('4th factorial number is 24', () => { | ||
expect(factorial(4)).toBe(24); | ||
}); | ||
test.skip('6th factorial number is 720', () => { | ||
expect(factorial(6)).toBe(720); | ||
}); | ||
test.skip('10th factorial number is 3628800', () => { | ||
expect(factorial(10)).toBe(3628800); | ||
}); | ||
test.skip('15th factorial number is 1307674368000', () => { | ||
expect(factorial(15)).toBe(1307674368000); | ||
}); | ||
test.skip('25th factorial number is 1.5511210043330986e+25', () => { | ||
expect(factorial(25)).toBe(1.5511210043330986e+25); | ||
}); | ||
test.skip('0th factorial number is 1', () => { | ||
expect(factorial(0)).toBe(1); | ||
}); | ||
test.skip("doesn't accept negatives", () => { | ||
expect(factorial(-25)).toBe(undefined); | ||
}); | ||
test.skip("doesn't accept floats", () => { | ||
expect(factorial(5.4)).toBe(undefined); | ||
}); | ||
test.skip("doesn't accept a number as a string", () => { | ||
expect(factorial('5')).toBe(undefined); | ||
}); | ||
test.skip("doesn't accept strings", () => { | ||
expect(factorial('foo')).toBe(undefined); | ||
}); | ||
test.skip("doesn't accept arrays", () => { | ||
expect(factorial([5])).toBe(undefined); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const factorial = function(n) { | ||
if (!Number.isInteger(n) || n < 0) return; | ||
if (n === 0) return 1; | ||
return n * factorial(n - 1); | ||
}; | ||
|
||
module.exports = factorial; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const factorial = require("./factorial-solution"); | ||
|
||
describe('factorial', () => { | ||
test('4th factorial number is 24', () => { | ||
expect(factorial(4)).toBe(24); | ||
}); | ||
test.skip('6th factorial number is 720', () => { | ||
expect(factorial(6)).toBe(720); | ||
}); | ||
test.skip('10th factorial number is 3628800', () => { | ||
expect(factorial(10)).toBe(3628800); | ||
}); | ||
test.skip('15th factorial number is 1307674368000', () => { | ||
expect(factorial(15)).toBe(1307674368000); | ||
}); | ||
test.skip('25th factorial number is 1.5511210043330986e+25', () => { | ||
expect(factorial(25)).toBe(1.5511210043330986e+25); | ||
}); | ||
test.skip('0th factorial number is 1', () => { | ||
expect(factorial(0)).toBe(1); | ||
}); | ||
test.skip('doesn\'t accept negatives', () => { | ||
expect(factorial(-25)).toBe(undefined); | ||
}); | ||
test.skip('doesn\'t accept floats', () => { | ||
expect(factorial(5.4)).toBe(undefined); | ||
}); | ||
test.skip('doesn\'t accept a number as a string', () => { | ||
expect(factorial('5')).toBe(undefined); | ||
}); | ||
test.skip('doesn\'t accept strings', () => { | ||
expect(factorial('foo')).toBe(undefined); | ||
}); | ||
test.skip('doesn\'t accept arrays', () => { | ||
expect(factorial([5])).toBe(undefined); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.