Is there a nice idiomatic way to iterate an array in Coffeescript but accessing both the current and the next item inside the loop? For example in Python you can do:
[f(current, next) for current, next in zip(a, a[1:])]
How about something like this?
array = ['a', 'b', 'c', 'd']
for value, index in array
current = value
next = if array[index+1] then array[index+1] else null
alert "#{current} at #{index} #{next}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With