+ 1

Ruby task- Help my explain why I receive output in this =7

What is the output of this code? *a,b= [1,2,3,4] Puts a[b-2] +b # output= 7 I just wh ant understand why?

27th Jun 2020, 6:17 AM
Андрей Рыбаков
Андрей Рыбаков - avatar
5 Respostas
+ 4
Андрей Рыбаков a is a list And a[2] means value at index 2 which is 3 As index start from 0.. a[0]=1 a[1]=2 a[2]=3
27th Jun 2020, 6:52 AM
Indira
Indira - avatar
+ 3
Yes. Indira's answer is an extremely clear answer.
27th Jun 2020, 7:03 AM
Андрей Рыбаков
Андрей Рыбаков - avatar
0
ok, But how did this expression turn into this a[2] --->3? a=1+2+3=6 6[2]--->6/2?
27th Jun 2020, 6:44 AM
Андрей Рыбаков
Андрей Рыбаков - avatar