/custom-for-each

Demonstrate what a forEach method might have for code to loop and call the callback

Primary LanguageJavaScript

A Custom Version of forEach for Sake of Learning

Why a custom function that works like forEach?

So we can better conceptualize how forEach works

Instructions

Follow the process we learned in https://github.com/SummerOfCode2020/week-04-forking-from-the-org

First

  • Fork
  • Clone your personal copy to your local
  • cd into the project
  • Run npm install
  • Note there were no dependencies for this project
  • Run npm start to see the output

Next Use the Debugger

  • In VS Code, add a breakpoint to line 66 in custom-for-each.js
  • In VS Code, Open package.json
  • Click the "Debug" icon that is above the scripts property
  • Select to debug the start script when prompted
  • Note the variables and the iteration logic we can see in the debugger
  • Click the play button for Continue. F8 is the shortcut key as another option
  • Note the changing variables
  • Repeat clicking Continue to see each iteration and it's variables

Then Change the Breakpoint

  • Remove previously set breakpoints
  • Add a breakpoint to line 102
  • Run the debugger again
  • Note the variables
  • Click the play button for Continue
  • Note the changing variables
  • Repeat clicking Continue to see each iteration and it's variables

Finally

We will plan to cover this in class to see how we can use this to understand what forEach does.

Master the forEach