3
I need, from a file . txt that has multiple tweets (one on each line), to read this file and put in a variable in the following format:
[1, "texto da primeira linha do arquivo"], [1, "texto da segunda linha"]
I was able to read the file and print it, but I cannot mount array array.
Thank you very much! Just a brief question. What does . map mean?
– Pedro Luiz Tortella
The map is very common in programming languages, and what it does is return each execution of the block within an array. For example:
[1, 2, 3].map {|number| number * 2 } # => [2, 4, 6]
– Peoplee
Got it! And what’s the difference for . each?
– Pedro Luiz Tortella
each does not return anything, using the previous example:
[1, 2, 3].each {|number| number * 2 } # => [1, 2, 3]
. To reproduce the result ofmap
using theeach
you would have to do + or - like this:tmp = []; [1, 2, 3].each {|number| tmp << number * 2 }; puts tmp # => [2, 4, 6]
. See more here: http://stackoverflow.com/questions/5254128/arrayeach-vs-arraymap– Peoplee
Thanks for the answers (:
– Pedro Luiz Tortella