How would one solve the following problem without Generators? I came across something like this in a project I'm working on that requires deep iteration in pairs. I've only been able to solve it with Generators.
nums is a sample input. The input is an array of arbitrary length made up of integers and other such arrays of arbitrary depth.
Iterate over nums in pairs of [beforeNum, nextNum]. This means that
the first pair's first value should be null ([null, 1]). The second
pair should be [1, 2], and so on. The final pair should be [10, 11].
Ultimately, my actual goal was to be able to get the nth individual "atom", regardless of how many levels deep it is. For example, get(nums, 6) would be 7.
const nums = [1, [2, 3, [4, [5, 6], 7], [8, 9, [10], 11]]];
Edit Figured it out with @hugomg's help. When I dove in, it turns out that the fact that I was actually implementing this with something much different than plain arrays was getting in my way. The solution's actually super straightforward: https://gist.github.com/jclem/fbd44c43cb175dbf880e
numsa sample input? Are inputs always a pair at any depth?