Add files via upload

This commit is contained in:
reddforman 2022-11-17 08:44:11 -08:00 committed by GitHub
parent 4366f7b039
commit d5e6e559cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 9 deletions

View File

@ -1,6 +1,31 @@
const fibonacci = function() {
const fibonacci = function(num) {
num = parseInt(num, 10);
if (num < 0) {
return "OOPS";
}
let first = 0;
let second = 1;
let next = 0;
let array = [1];
for (let i = 1; i < num; i++) {
next = first + second;
first = next;
array.push(next);
next = first + second;
second = next;
array.push(next);
}
return array[num -1];
};
// 1, 1, 2, 3, 5, 8, 13, 21
// Do not edit below this line
module.exports = fibonacci;

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);
});
});