Over the course of learning any programming language you will inevitably run into loops. They are a foundational part of all computing and for the most part seem pretty straight forward. Today I thought we would take a look at a situation where things aren’t as straight forward and figuring out the loops might just drive you loopy (Ill be here all week :/).
Here are the problems:
Write a function called map2 that accepts two arrays and a function as arguments, and constructs a new array by invoking its function argument on the elements of both arrays, e.g.:
This first problem is fairly easy and straight forward but lets break it down so we know exactly where we are at.
Ok pretty easy. Now for the hard stuff…
Now, write a function called mapN that accepts an arbitrary number of arrays and a n-ary function as arguments, and constructs a new array by combining the elements of all the arrays, e.g.:
note: You’ll need to read about the arguments keyword and apply to complete this function.