Skip to Content
Mastering JavaScript Functional Programming
book

Mastering JavaScript Functional Programming

by Federico Kereki
November 2017
Intermediate to advanced
386 pages
9h 22m
English
Packt Publishing
Content preview from Mastering JavaScript Functional Programming

Questions

4.1. Minimalistic function: Functional programmers sometimes tend to write code in a minimalistic way. Can you examine this version of the Fibonacci function, and explain whether it works, and if so, how?

     const fib2 = n => (n < 2 ? n : fib2(n - 2) + fib2(n - 1));

4.2. A cheap way: The following version of the Fibonacci function is quite efficient and doesn't do any unnecessary or repeated computations. Can you see how? Suggestion: try to calculate fib4(6) by hand, and compare with the example given earlier in the book:

     const fib4 = (n, a = 0, b = 1) => (n === 0 ? a : fib4(n - 1, b, a        + b));

4.3 A shuffle test: How would you write unit tests for shuffle(), to test whether it works correctly with arrays with repeated values?

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering JavaScript Functional Programming - Second Edition

Mastering JavaScript Functional Programming - Second Edition

Federico Kereki

Publisher Resources

ISBN: 9781787287440Supplemental Content