yonran yonran - 1 year ago 111
CoffeeScript Question

enumerate and zip within Coffeescript?

Coming from Python, I like many of the features that Coffeescript borrows from Python and Perl (ranges/slices, comprehensions, destructuring assignments). Is there any syntactic sugar in Coffeescript to mimic Python's

) functions?

Here are the patterns that I don't care much for:

# an enumerate call would be helpful here
i = 0
for x in arr
... use x and i ...


# a zip would be useful here
n = Math.min(arr1.length,arr2.length)
for i in 0...n
x = arr1[i]; y = arr2[i]
... use x and y ...

Answer Source

forEach is effectively built in:

a = ['a','b','c']
for el,i in a
    alert "Element #{el} is at index #{i}"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download