Completed fibonacci

This commit is contained in:
Roberra0 2023-07-07 18:22:45 -07:00
parent ed5387f268
commit da7479ac27
2 changed files with 9 additions and 6 deletions

View File

@ -4,8 +4,11 @@ const fibonacci = function(n) {
//n4 = n3+n2
//n3 = n2+n1
//n2 = n1
if(n<0){
return "OOPS";
}
if(n<=1){
return n;
return Number(n);
}
return fibonacci(n-1)+fibonacci(n-2);
};

View File

@ -13,19 +13,19 @@ describe('fibonacci', () => {
test('15th fibonacci number is 610', () => {
expect(fibonacci(15)).toBe(610);
});
test.skip('25th fibonacci number is 75025', () => {
test('25th fibonacci number is 75025', () => {
expect(fibonacci(25)).toBe(75025);
});
test.skip('doesn\'t accept negatives', () => {
test('doesn\'t accept negatives', () => {
expect(fibonacci(-25)).toBe("OOPS");
});
test.skip('DOES accept strings', () => {
test('DOES accept strings', () => {
expect(fibonacci("1")).toBe(1);
});
test.skip('DOES accept strings', () => {
test('DOES accept strings', () => {
expect(fibonacci("2")).toBe(1);
});
test.skip('DOES accept strings', () => {
test('DOES accept strings', () => {
expect(fibonacci("8")).toBe(21);
});
});