Hello, I am fairly new to Ruby and I’m trying to learn it on my own. I
have a block of code that i have a question about, see below:
array = [1, 2, 3, 4]
array.collect! do |n|
n ** 4
end
puts array.inspect
My question is about n4, if i run this code it gives me “[1, 16, 81,
256]”, whats happening here? 4 x 4 is 16 why is the last element 256,
i thought n4 would multiply the elements by 4. Obviously I was wrong.
Help me understand this Please.
Hello, I am fairly new to Ruby and I’m trying to learn it on my own. I
have a block of code that i have a question about, see below:
array = [1, 2, 3, 4]
array.collect! do |n|
n ** 4
end
puts array.inspect
My question is about n4, if i run this code it gives me “[1, 16, 81,
256]”, whats happening here? 4 x 4 is 16 why is the last element 256,
i thought n4 would multiply the elements by 4. Obviously I was wrong.
Help me understand this Please.