Upto isn’t bad, but id probably use inject: [1,2,3].inject ([]) {|arr,
elem|
arr << arr.last + elem}
I typed this on my phone, so apologies if it’s slightly off.
Upto isn’t bad, but id probably use inject: [1,2,3].inject ([]) {|arr,
elem|
arr << arr.last + elem}
I typed this on my phone, so apologies if it’s slightly off.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs