Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write the fibonacci function where indicated. The fibonacci function should have one parameter named n and return the nth Fibonacci number: If n is a

Write the fibonacci function where indicated. The fibonacci function should have one parameter named n and return the nth Fibonacci number: If n is a nonnegative integer (positive or zero): If n is less than 2, the function should return the value of n. This is the base case and will ensure that the recursion eventually stops. Otherwise, the function should return the sum of fibonacci(n - 2) and fibonacci(n - 1). This is the recursive step. If n is not an integer or is a negative number, the function should return the default value of 0. Here are some values to use when testing your code: The 10th Fibonacci number is 55. The 20th Fibonacci number is 6765. The 30th Fibonacci number is 832040. The On-Line Encyclopedia of Integer Sequences has even more values to test with. When testing, don't bother trying input numbers greater than about 40. This recursive algorithm has an exponential running time and is very slow for larger inputs.

I need help with the function, in javascript. so far I have

function fibonacci(num){ if(num < 2){ return num; }else{ return fibonacci(num-2)+ fibonacci(num-1); //returning the sum of fibonacci numbers } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Automating Access Databases With Macros

Authors: Fish Davis

1st Edition

1797816349, 978-1797816340

More Books

Students also viewed these Databases questions

Question

=+Is the fear relevant to the issue?

Answered: 1 week ago

Question

=+ Should the MNE belong (why, why not)?

Answered: 1 week ago

Question

=+ What is the role of government in bargaining?

Answered: 1 week ago