How to write your own Javascript forEach method – Part 1

Learning to write your own forEach method in Javascript

A while back, I went to New York City to a free coding class at the Hack Reactor Bootcamp.  Occasionally, they offer free one night classes on various topics.  This one was the higher-order-functions workshop and after some lecture and the expected (and appropriate) marketing of apply-to-hack-reactor, we all downloaded a git repo with an assignment and some tests that we had to have our code pass.  The basic idea was to write your own array methods including forEach, filter, map, and reduce. The idea was to get one to gain a fuller understanding of what was going on ‘under the hood’ when calling these methods.

I’m still not sure if the recent grad/presenter wasn’t clear with the instructions or if maybe we all had a little less previous Javascript experience than was expected (probably a bit of both) but she was met with quite a few puzzled faces, myself included.  After a little more explanation and a few hints on how to get started, we began to make some progress but the session came to a close before anyone had a chance to finish.

As for myself, I managed to get through forEach but was stumped on how to actually use it to complete the next few methods, which was a requirement of the rest of the assignment.  I’ve spent quite a bit of time on these and really think I have a much better understanding of how they work.  So my few posts will be an attempt to explain not only how to code each of these methods but hopefully give you a deeper understanding of what is going on behind the curtain.

I have since seen this same basic assignment in several different places online such as a free mini-boot camp from Lambda School, online tutorials, etc. so it’s not unique to Hack Reactor but here is the Hack Reactor higher-order functions workshop git repo.  I’m assuming they don’t mind this being shared since it is after all in a public repo, but I will add that if I could afford it I would love to go to Hack Reactor and you should definitely apply! 🙂

I’ll put my solution code and explanation in a separate post.


This website is created with Gatsby by Alex Nielsen. I am currently seeking full-time web development positions in the New York City/New Jersey area.