Questions
7.1 Hard by hand: With our “curried by hand” sum()
function, we could write sum()(3)(5)
and get 8
. But what happens if we write sum(3)()(5)
instead?
7.2 Sum as you will: The following exercise will help you understand some of the concepts we dealt with in this chapter, even if you solve it without using any of the functions we looked at. Write a sumMany()
function that lets you sum an indeterminate quantity of numbers in the following fashion. Note that when the function is called with no arguments, the sum is returned:
let result = sumMany(9)(2)(3)(1)(4)(3)(); // 22
7.3 Curry with eval? You could also produce a curried version of a function by using eval()
– yes, the unsafe, dangerous eval()
! If you are willing to avoid the potential security headaches that eval()
can bring, you could use it to transform a function such as the following:
const make3 = (a: string, b: number, c: string): string => `${a}:${b}:${c}`;
You could...