persons.each_cons(2) do |person| if person[0] == person[1] #SKIP 2 iterations end puts "Howdy? #{person[0]}"end解决方法 你不能直接这样做.
您可能想要在阵列上调用uniq
,或者如果订单很重要,请查看新的chunk
方法:
[1,1,2,3].uniq # => [1,3][1,3].chunk{|e| e}.map(&:first) # => [1,3]# i.e. two adjacent items will always be different总结
以上是内存溢出为你收集整理的ruby – 跳过Enumerable#each_cons中的’n’次迭代全部内容,希望文章能够帮你解决ruby – 跳过Enumerable#each_cons中的’n’次迭代所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)