8000 Merge pull request #396 from jamienorthman/main · daygoDao/javascript-exercises@b8b1ae4 · GitHub
[go: up one dir, main page]

Skip to content

Commit b8b1ae4

Browse files
Merge pull request TheOdinProject#396 from jamienorthman/main
10_fibonacci: handling of string zero & update of tests
2 parents a3992aa + a27f662 commit b8b1ae4

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

10_fibonacci/fibonacci.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@ 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);
21+
});
1922
test.skip('doesn\'t accept negatives', () => {
2023
expect(fibonacci(-25)).toBe("OOPS");
2124
});
25+
test.skip('DOES accept strings', () => {
26+
expect(fibonacci("0")).toBe(0);
27+
});
2228
test.skip('DOES accept strings', () => {
2329
expect(fibonacci("1")).toBe(1);
2430
});

10_fibonacci/solution/fibonacci-solution.js

Lines changed: 11 additions & 2 deletions
< 10000 /thead>
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1-
const fibonacci = function(count) {
1+
const fibonacci = function(countArg) {
2+
// checks argument's type and makes sure we use
3+
// a number throughout rest of function.
4+
let count
5+
if (typeof countArg !== 'number') {
6+
count = parseInt(countArg)
7+
} else {
8+
count = countArg
9+
}
10+
211
if (count < 0) return "OOPS";
3-
if (count === 0) return 0;
12+
if (count == 0) return 0;
413

514
let firstPrev = 1;
615
let secondPrev = 0;

10_fibonacci/solution/fibonacci-solution.spec.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const fibonacci = require('./fibonacci-solution');
1+
const fibonacci = require('./fibonacci-solution')
22

33
describe('fibonacci', () => {
44
test('4th fibonacci number is 3', () => {
@@ -16,19 +16,22 @@ describe('fibonacci', () => {
1616
test('25th fibonacci number is 75025', () => {
1717
expect(fibonacci(25)).toBe(75025);
1818
});
19-
test('0th fibonacci number is o', () => {
19+
test('0th fibonacci number is 0', () => {
2020
expect(fibonacci(0)).toBe(0);
2121
});
22-
test("doesn't accept negatives", () => {
23-
expect(fibonacci(-25)).toBe('OOPS');
22+
test('doesn\'t accept negatives', () => {
23+
expect(fibonacci(-25)).toBe("OOPS");
2424
});
2525
test('DOES accept strings', () => {
26-
expect(fibonacci('1')).toBe(1);
26+
expect(fibonacci("0")).toBe(0);
2727
});
2828
test('DOES accept strings', () => {
29-
expect(fibonacci('2')).toBe(1);
29+
expect(fibonacci("1")).toBe(1);
3030
});
3131
test('DOES accept strings', () => {
32-
expect(fibonacci('8')).toBe(21);
32+
expect(fibonacci("2")).toBe(1);
3333
});
34-
});
34+
test('DOES accept strings', () => {
35+
expect(fibonacci("8")).toBe(21);
36+
});
37+
});

0 commit comments

Comments
 (0)
0