Create a function that returns a specific member of the Fibonacci sequence

This commit is contained in:
Akutsang 2023-02-03 23:45:35 +01:00
parent ca7b05549c
commit 8339f3e8d2
2 changed files with 17 additions and 9 deletions

View File

@ -1,4 +1,12 @@
const fibonacci = function() {
const fibonacci = function(n) {
if (n <= 1) {
return Number(n);
}
if (n < 0) {
return "opps"
}
return fibonacci(n - 1) + fibonacci(n - 2)
};

View File

@ -4,28 +4,28 @@ describe('fibonacci', () => {
test('4th fibonacci number is 3', () => {
expect(fibonacci(4)).toBe(3);
});
test.skip('6th fibonacci number is 8', () => {
test('6th fibonacci number is 8', () => {
expect(fibonacci(6)).toBe(8);
});
test.skip('10th fibonacci number is 55', () => {
test('10th fibonacci number is 55', () => {
expect(fibonacci(10)).toBe(55);
});
test.skip('15th fibonacci number is 610', () => {
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);
});
});