Questions
6.1 Go with arrows: We implemented addLogging()
using a function, and its typing was not simple. Just to deal with a different syntax, can you provide an alternate implementation of addLogging()
but using an arrow function?
6.2 Mapping for memory: We implemented our memoizing functions by using an object as a cache. However, using a map would be better; make the necessary changes.
6.3 How many? How many calls would be needed to calculate fib(50)
without memoizing? For example, one call and no further recursion were needed to calculate fib(0)
or fib(1)
, and 25 calls were required for fib(6)
. Can you find a formula to do this calculation?
6.4 A randomizing balancer: Write an HOF, that is, randomizer(fn1, fn2, ...)
, that will receive a variable number of functions as arguments and return a new function that will, on each call, randomly call one of fn1
, fn2
, and so on. You could use this to balance calls to different services on a server if each function did an AJAX...