General Flashcards
1
Q
MULTIPLY EACH ITEM IN A LIST BY 2
A
(1..10).map { |n| n * 2 }
How does this work?
2
Q
Sum a list of numbers
A
(1..1000).inject(:+)
Explain your code.
3
Q
words = ["scala", "akka", "play framework", "sbt", "typesafe"]
tweet = "This is an example tweet talking about scala and sbt."
Which words in words
is in tweet
?
A
words.any? { |word| tweet.include?(word) }
Explain your code: ie, how does this work?
4
Q
Read the lines of a file into an array of strings
A