- 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 index.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. Hint: Check the test file to know the signature of the findFn and the type of its return value
Good luck!
View Exiting Loops Lab on Learn.co and start learning to code for free.