mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
adding 'by' to array comprehensions
This commit is contained in:
parent
b795ae7fe1
commit
decaea0f5f
2 changed files with 9 additions and 2 deletions
|
@ -848,8 +848,9 @@ module CoffeeScript
|
|||
for_part = "#{index_var}=0, #{source.compile(o.merge(:index => ivar, :step => @step))}, #{index_var}++"
|
||||
else
|
||||
index_var = nil
|
||||
source_part = "#{svar} = #{source.compile(o)};\n#{idt}"
|
||||
for_part = @object ? "#{ivar} in #{svar}" : "#{ivar} = 0; #{ivar} < #{svar}.length; #{ivar}++"
|
||||
source_part = "#{svar} = #{@source.compile(o)};\n#{idt}"
|
||||
step_part = @step ? "#{ivar} += #{@step.compile(o)}" : "#{ivar}++"
|
||||
for_part = @object ? "#{ivar} in #{svar}" : "#{ivar} = 0; #{ivar} < #{svar}.length; #{step_part}"
|
||||
var_part = "#{body_dent}#{@name} = #{svar}[#{ivar}];\n" if @name
|
||||
# body.unshift(AssignNode.new(@name, ValueNode.new(svar, [IndexNode.new(ivar)]))) if @name
|
||||
end
|
||||
|
|
|
@ -40,3 +40,9 @@ for method in methods
|
|||
print obj.one() is "I'm one"
|
||||
print obj.two() is "I'm two"
|
||||
print obj.three() is "I'm three"
|
||||
|
||||
|
||||
# Steps should work for array comprehensions.
|
||||
|
||||
array: [0..10]
|
||||
print num % 2 is 0 for num in array by 2
|
||||
|
|
Loading…
Add table
Reference in a new issue