Assignments JS.Recursion

Handing In Assignments

You must hand in by using git

Hand In by git

  • Create an empty repo on bitbucket.org, gitlab.com, or github.com,
  • git push your local repo to the above remote repo.
  • For node assignments please put the line(s)

    node_modules/

    into your .gitignore file.

Send a mail to with:

  • The word 'handin <subjectname>' in the subject line of your mail
  • The url of your repo(s).

Assignment JS.Recursion.0

There is a mathematical koncept, factorial, important in probability and statistics. The definition of n!:

n! = n * (n-1) * (n - 2) * ... * 2 * 1

There is a genuinely recursive definition that is, perhaps, more elegant:

n! = n * (n - 1)!

Write a recursive function fact(n) that calculates the factorial of a given natural number n. Document it with a couple of testcases. Place the function in myRecurseLib.js.

Ref: https://en.wikipedia.org/wiki/Factorial

Assignment JS.Recursion.1

There is a mathematical koncept, Fibonacci numbers, important in various contexts eg closely related to calculating the golden ratio. The definition of the n-th Fibonacci number Fn:

F0 = 0; F1 = 1;

and:

Fn = Fn-1 + Fn-2

Write a recursive function fibo(n) that calculates the n-th Fibonacci number. Document it with a couple of testcases. Save the function in myRecurseLib.js.

Ref: https://en.wikipedia.org/wiki/Fibonacci_number

Assignment JS.Recursion.2

The mathematical powers, eg 27, or 34 may be calculated recursively.

Write a recursive function pow(r, e) that calculates re. It must work for r ∈ ℕ, and e ∈ ℕ. You might test whether it also works for r ∈ ℤ, and e ∈ ℤ

Put it into your myRecurseLib.js.