You'll notice that if you play the game, the second segment always just
moves down. This is OK for now!
array.forEach allows us to call a function with each item in a collection.
This is a very common kind of loop and is very powerful.
array.push adds the element it is given to the array it is called in.
is another kind of loop that makes it easy to build a new collection from an
existing collection. Rewrite the moveSnake function to use array.map
instead of array.forEach
loops are also quite common. They are more generally useful but harder to use
than the collection based forEach and map functions. How could you write
moveSnake with either for or while?