Great write-up! Another way to get a feeling for what, and how, map works is to try to re-implement it in terms of each, something like this
defmy_map(array)# we'll be returning another arrayresponse=[]# for each element in the arrayarray.eachdo|element|# yield/pass element to the provided block, push the result into responseresponse<<(yieldelement)end# return the responseresponseend=>:my_map# kick the tires and double every item in the list:my_map([1,2,3,4,5]){|x|x*2}=>[2,4,6,8,10]
The actual implementation of map in the usual ruby interpreter is done in C for efficiency, but you could build it from each instead (and it helps sometimes to have examples of the concept written in the same language you're working with).
For further actions, you may consider blocking this person and/or reporting abuse
Great write-up! Another way to get a feeling for what, and how, map works is to try to re-implement it in terms of
each
, something like thisThe actual implementation of map in the usual ruby interpreter is done in C for efficiency, but you could build it from
each
instead (and it helps sometimes to have examples of the concept written in the same language you're working with).