Learn JavaScript

Lesson 6 of 9 · Functions: Declarations, Arrows, Defaults and Rest

Module 5 · Functions: Declarations, Arrows, Defaults and Rest

CP and Interview Pack: Recursion Patterns, Currying and the Bug Gallery

ProReading

Alice's take-home test has one line that worries her: "Compute 2 to the power 1,000,000, modulo 1,000,007, without a loop of a million." Bob says it cannot be done. Amara says it takes 21 calls. By the end of the second pattern you will see why Amara is right. You will also see why Bob's first idea, a recursion that multiplies by 2 a million times, cannot even run on Node.

Checking what this lesson needs for you…

What is inside CP and Interview Pack: Recursion Patterns, Currying and the Bug Gallery

  1. Pattern 1: the smaller input
  2. Pattern 2: halving, with fast power
  3. Pattern 3: include or exclude
  4. Pattern 4: memoisation, previewed
  5. The interview questions, with model answers
  6. Currying: add(1)(2)(3)
  7. Debounce, previewed with setTimeout
  8. What does this print?
  9. The contest angle
CP and Interview Pack: Recursion Patterns, Currying and the Bug Gallery | Learn JavaScript | Progsity