Completed fibonacci
This commit is contained in:
parent
ed5387f268
commit
da7479ac27
|
@ -4,8 +4,11 @@ const fibonacci = function(n) {
|
||||||
//n4 = n3+n2
|
//n4 = n3+n2
|
||||||
//n3 = n2+n1
|
//n3 = n2+n1
|
||||||
//n2 = n1
|
//n2 = n1
|
||||||
|
if(n<0){
|
||||||
|
return "OOPS";
|
||||||
|
}
|
||||||
if(n<=1){
|
if(n<=1){
|
||||||
return n;
|
return Number(n);
|
||||||
}
|
}
|
||||||
return fibonacci(n-1)+fibonacci(n-2);
|
return fibonacci(n-1)+fibonacci(n-2);
|
||||||
};
|
};
|
||||||
|
|
|
@ -13,19 +13,19 @@ describe('fibonacci', () => {
|
||||||
test('15th fibonacci number is 610', () => {
|
test('15th fibonacci number is 610', () => {
|
||||||
expect(fibonacci(15)).toBe(610);
|
expect(fibonacci(15)).toBe(610);
|
||||||
});
|
});
|
||||||
test.skip('25th fibonacci number is 75025', () => {
|
test('25th fibonacci number is 75025', () => {
|
||||||
expect(fibonacci(25)).toBe(75025);
|
expect(fibonacci(25)).toBe(75025);
|
||||||
});
|
});
|
||||||
test.skip('doesn\'t accept negatives', () => {
|
test('doesn\'t accept negatives', () => {
|
||||||
expect(fibonacci(-25)).toBe("OOPS");
|
expect(fibonacci(-25)).toBe("OOPS");
|
||||||
});
|
});
|
||||||
test.skip('DOES accept strings', () => {
|
test('DOES accept strings', () => {
|
||||||
expect(fibonacci("1")).toBe(1);
|
expect(fibonacci("1")).toBe(1);
|
||||||
});
|
});
|
||||||
test.skip('DOES accept strings', () => {
|
test('DOES accept strings', () => {
|
||||||
expect(fibonacci("2")).toBe(1);
|
expect(fibonacci("2")).toBe(1);
|
||||||
});
|
});
|
||||||
test.skip('DOES accept strings', () => {
|
test('DOES accept strings', () => {
|
||||||
expect(fibonacci("8")).toBe(21);
|
expect(fibonacci("8")).toBe(21);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue