Methods and hints on the go Flashcards

1
Q

how to check x is an integer?

A

x.is_a? Integer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

how to add elements to an array?

A

my_array.push(“element”)
or
my_array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

apply a block on each element of an array

A

my_array.collect { |x| x *2 }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

apply a block on each element of an array that meets a condition

A

my_array.select { |x| x % 2 == 0 }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

apply a block on each element of an array that does not meet a condition

A

my_array.reject { |x| x > 2 }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly