gpt4 book ai didi

list-comprehension - 枚举并在Coffeescript中压缩?

转载 作者:行者123 更新时间:2023-12-03 08:54:40 25 4
gpt4 key购买 nike

来自Python,我喜欢Coffeescript从Python和Perl借来的许多功能(范围/ slice ,理解,破坏性分配)。 Coffeescript中是否有任何语法糖可以模仿Python的enumeratezip(itertools.izip)函数?

以下是我不太关心的模式:

# an enumerate call would be helpful here
i = 0
for x in arr
... use x and i ...
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 ...

最佳答案

forEach有效地内置于:

a = ['a','b','c']
for el,i in a
alert "Element #{el} is at index #{i}"

关于list-comprehension - 枚举并在Coffeescript中压缩?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5615887/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com