Ruby Data Processing: Using Map, Reduce, and Select by Jay Godse

Ruby Data Processing: Using Map, Reduce, and Select by Jay Godse

Author:Jay Godse [Jay Godse]
Language: eng
Format: epub
Tags: Core Programming, Web Development
Publisher: Apress
Published: 2018-02-18T22:00:00+00:00


First, this is obviously a two-dimensional array. So, it will look something like this for a four-row triangle:

[[1],[1,1],[1,2,1],[1,3,3,1]]

For convenient printing, we’ll just do this for now:

triangle.each{|row| p row.inspect}

Given that we’re building a structure of arrays, it seems like a good fit for using reduce(). The initial value is [].

triangle = (0..5).reduce([]) do |memo, n|

memo.push []

end

triangle.each{|row| p row.inspect}

"[]"

"[]"

"[]"

"[]"

"[]"

"[]"

=> [[], [], [], [], [], []]



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.