+ 1
Adding some numbers to arry[RUBY]
When I wanted to add [6,7,8] to [3,4,8,15] the output was [3,4,8,15,6,7,8] , Is it correct? because I think the compiler avoid to puts 8 into arry two times! https://code.sololearn.com/cJoljaa9CeN2/?ref=app
3 Respuestas
+ 7
No, the output is correct. Both array's elements are merged(added) and the combined array is assigned to variable a.
a = [3, 4, 8, 15] # assign a to an array of numbers
a += [6, 7, 8] # which is equivalent to a = a + [6, 7, 8]
# which becomes a = [3, 4, 8, 15] + [6, 7, 8]
# merge the two arrays and assign the new value to a
a = [3, 4, 8, 15, 6, 7, 8]
if you want to add the numbers in them check the below SO questions. it does just that.
https://stackoverflow.com/questions/12584585/adding-two-ruby-arrays
If you aren't familiar with the "+=" operator then read the below resource it explains the functionality of all ruby operators
https://www.tutorialspoint.com/ruby/ruby_operators.htm
+ 1
Thank you I figure out☺