Skip to content

Commit 1ec6206

Browse files
authored
Merge pull request #694 from TheOdinProject/fix/update_fibonacci
03_fibonacci: Update exercise to return "OOPS" for 0
2 parents c54c9c1 + b9dc0f9 commit 1ec6206

4 files changed

Lines changed: 8 additions & 12 deletions

File tree

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Exercise 03 - Fibonacci
22

3-
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
3+
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>
44

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

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

12-
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.
12+
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.

‎foundations/object_basics/03_fibonacci/fibonacci.spec.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ describe('fibonacci', () => {
1616
test.skip('25th fibonacci number is 75025', () => {
1717
expect(fibonacci(25)).toBe(75025);
1818
});
19-
test.skip('0th fibonacci number is 0', () => {
20-
expect(fibonacci(0)).toBe(0);
19+
test.skip('doesn\'t accept 0', () => {
20+
expect(fibonacci(0)).toBe("OOPS");
2121
});
2222
test.skip('doesn\'t accept negatives', () => {
2323
expect(fibonacci(-25)).toBe("OOPS");

‎foundations/object_basics/03_fibonacci/solution/fibonacci-solution.js‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
const fibonacci = function(count) {
22
// checks argument's type and makes sure we use
3-
// a number throughout rest of function.
4-
if (typeof count !== 'number' || count < 0 || Number.isNaN(count)) {
3+
// a positive number throughout rest of function.
4+
if (typeof count !== 'number' || count <= 0 || Number.isNaN(count)) {
55
return "OOPS";
66
}
7-
8-
if (count === 0) {
9-
return 0;
10-
}
117

128
let firstPrev = 1;
139
let secondPrev = 0;

‎foundations/object_basics/03_fibonacci/solution/fibonacci-solution.spec.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ describe('fibonacci', () => {
1616
test('25th fibonacci number is 75025', () => {
1717
expect(fibonacci(25)).toBe(75025);
1818
});
19-
test('0th fibonacci number is 0', () => {
20-
expect(fibonacci(0)).toBe(0);
19+
test('doesn\'t accept 0', () => {
20+
expect(fibonacci(0)).toBe("OOPS");
2121
});
2222
test('doesn\'t accept negatives', () => {
2323
expect(fibonacci(-25)).toBe("OOPS");

0 commit comments

Comments
 (0)