The code defines two functions, `eachTimesFn` and `mapTimesFn`. The `eachTimesFn`...
The code defines two functions, eachTimesFn
and mapTimesFn
. The eachTimesFn
function takes in a count and an iterator function, and executes the iterator function count
number of times, passing in the index to the iterator function each time. If the count is falsy (e.g. zero), then it returns an empty array.
The mapTimesFn
function takes in a count and an iterator function, and creates an empty array called result
. It then calls eachTimesFn
with the count and an anonymous function that takes in the index, calls the iterator function with the index, and pushes the result onto the result
array. Finally, it returns the result
array.
The code then calls mapTimes
with an anonymous function that takes in an index
parameter. Within the function, it initializes a variable pt
, updates the angle
variable, calculates x
and y
coordinates using the legLength
and angle
, and updates legLength
. Finally, it returns the pt
object. Since mapTimes
is calling this anonymous function for each index from 0 to count - 1
, the returned objects are added to the result
array and ultimately returned by mapTimesFn
.