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
4 changes: 2 additions & 2 deletions foundations/object_basics/03_fibonacci/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Exercise 03 - Fibonacci

Create a function that returns a specific member of the Fibonacci sequence (series of numbers in which each number is the sum of the two preceding numbers). To learn more about Fibonacci sequences, go to: https://en.wikipedia.org/wiki/Fibonacci_sequence
Create a function that returns a specific member of the Fibonacci sequence (series of numbers in which each number is the sum of the two preceding numbers). To learn more about Fibonacci sequences, go to: <https://en.wikipedia.org/wiki/Fibonacci_sequence>

In this exercise, the Fibonacci sequence used is 1, 1, 2, 3, 5, 8, etc. (i.e. starting at 1, not 0):

Expand All @@ -9,4 +9,4 @@ fibonacci(4); // returns the 4th member of the series: 3 (1, 1, 2, 3)
fibonacci(6); // returns 8
```

If given a negative number, `NaN`, or not a number type at all, the function should return `"OOPS"`, i.e. only proceed with positive numbers.
If given 0, a negative number, `NaN`, or not a number type at all, the function should return `"OOPS"`, i.e. only proceed with positive numbers.
4 changes: 2 additions & 2 deletions foundations/object_basics/03_fibonacci/fibonacci.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ describe('fibonacci', () => {
test.skip('25th fibonacci number is 75025', () => {
expect(fibonacci(25)).toBe(75025);
});
test.skip('0th fibonacci number is 0', () => {
expect(fibonacci(0)).toBe(0);
test.skip('doesn\'t accept 0', () => {
expect(fibonacci(0)).toBe("OOPS");
});
test.skip('doesn\'t accept negatives', () => {
expect(fibonacci(-25)).toBe("OOPS");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
const fibonacci = function(count) {
// checks argument's type and makes sure we use
// a number throughout rest of function.
if (typeof count !== 'number' || count < 0 || Number.isNaN(count)) {
// a positive number throughout rest of function.
if (typeof count !== 'number' || count <= 0 || Number.isNaN(count)) {
return "OOPS";
}

if (count === 0) {
return 0;
}

let firstPrev = 1;
let secondPrev = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ describe('fibonacci', () => {
test('25th fibonacci number is 75025', () => {
expect(fibonacci(25)).toBe(75025);
});
test('0th fibonacci number is 0', () => {
expect(fibonacci(0)).toBe(0);
test('doesn\'t accept 0', () => {
expect(fibonacci(0)).toBe("OOPS");
});
test('doesn\'t accept negatives', () => {
expect(fibonacci(-25)).toBe("OOPS");
Expand Down
Loading