D
David Heinemeier Hansson
Consider:
%w{ one two three }.inject(Array.new) { |a, e| a << e if e != "three" }
I would have expected that to return:
[ "one", "two" ]
Instead it returns nil.
What am I missing? Or isn't it possible to use conditions in an inject
expression? If not, how would one go about archiving the same?
/ David
%w{ one two three }.inject(Array.new) { |a, e| a << e if e != "three" }
I would have expected that to return:
[ "one", "two" ]
Instead it returns nil.
What am I missing? Or isn't it possible to use conditions in an inject
expression? If not, how would one go about archiving the same?
/ David