Turn forEach() into a map()
Use utils.merge()
Use .concat() instead of mutating with .push()
Use recursion instead of a while loop that pushes to the array