Methods and hints on the go Flashcards
1
Q
how to check x is an integer?
A
x.is_a? Integer
2
Q
how to add elements to an array?
A
my_array.push(“element”)
or
my_array
3
Q
apply a block on each element of an array
A
my_array.collect { |x| x *2 }
4
Q
apply a block on each element of an array that meets a condition
A
my_array.select { |x| x % 2 == 0 }
5
Q
apply a block on each element of an array that does not meet a condition
A
my_array.reject { |x| x > 2 }