Skip to content

Commit 80ca665

Browse files
committed
added explicit conversion to number for fibonacci solution
1 parent 4a03e41 commit 80ca665

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

10_fibonacci/solution/fibonacci-solution.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
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";
312
if (count == 0) return 0;
413

@@ -14,4 +23,4 @@ const fibonacci = function(count) {
1423
return firstPrev;
1524
};
1625

17-
module.exports = fibonacci;
26+
module.exports = fibonacci;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ describe('fibonacci', () => {
3434
test('DOES accept strings', () => {
3535
expect(fibonacci("8")).toBe(21);
3636
});
37-
});
37+
});

0 commit comments

Comments
 (0)