Reputation: 139
dictionary = File.foreach('dictionary.txt').map { |line| line.split('\n') }
dictionary.each{|word|
puts word.length
if word.length == 5
puts word
end
}
It says the value for each |word| is only 1. Anyone have a clue why? Thanks.
Upvotes: 0
Views: 447
Reputation: 225164
You’re mapping a function that splits a line into lines to every line. Each line will contain one line, resulting in a one-element array. Maybe you meant line.chomp
?
dictionary = File.foreach('dictionary.txt').map &:chomp
Upvotes: 1