- Practice using
break
to exit a loop - Practice using
continue
to skip an iteration - Practice using
return
in a loop
Now that we've had some practice breaking out of loops, it's time to break free and practice a bit without training wheels.
In loops.js
, you'll have to define a few functions:
breakOut(array, changeValue, stopValue)
which iterates througharray
and changes every element tochangeValue
until the loop reachesstopValue
. Then webreak
out of the loop and return the array.keepGoing(array, changeValue, skipValue)
which iterates througharray
and changes every element tochangeValue
except those that matchskipValue
. Then return the array.findBy(array, findFn)
which looks for a value inarray
based on the return value offindFn
. Returnnull
if the value isn't found.
Good luck!