canadalearningcode / llc-intro-to-ruby

Intro to Data Analysis with Ruby -- (SLIDES - http://ladieslearningcode.github.io/llc-intro-to-ruby/slides.html), (LEARNER FILES - http://bit.ly/llc-ruby-data) - No sample project.
Other
7 stars 10 forks source link

Simplify looping over CSV data; Explain Arrays #14

Closed jleben closed 5 years ago

jleben commented 5 years ago

Previously, looping over CSV was done using this pattern:

CSV.foreach("file.csv") do |row| ...

While a built-in syntax for elem in range is introduced earlier, this introduces a new looping syntax, which has proven to be a burden and a distraction for learners. These changes avoid this burden by sticking to the built-in for loop throughout the slides.

Moreover, a couple slides explaining arrays are added. Since spreadsheets are a well-known analogy to the CSV data model, we read the entire CSV data into a 2-dimensional array (array of arrays) where values can be addressed like cells in a spreadsheet - by "row" and "column" index. A slide is also added that presents the CSV data in a table to reinforce the spreadsheet analogy.

Although it is generally more efficient to process data on the fly, if possible, I believe the approach taken here is at the same time easier to understand and provides more insight into the nature of arrays.

Exercises 4 and 5 are adjusted accordingly.