- 1

Challenge or quiz question

What is the output of this code? arr = [1, 6, 4, 2] print arr.take(arr.last) answer is [1, 6] I don't get it. Last should't it be 2? There are plenty of challenge questions I don't understand. Not sure if I should be posting new questions for all challenge explanations or just use one new question thread?

15th Jan 2018, 3:23 AM
Jeffrey Koh
Jeffrey Koh - avatar
2 Answers
+ 2
Thank you John Wells. I will post future questions related to such topics here. I just posted another one before I saw this.
15th Jan 2018, 5:02 AM
Jeffrey Koh
Jeffrey Koh - avatar
0
arr.last returns 2 and arr.take(2) yields the first two elements. It makes sense to continue using this thread.
15th Jan 2018, 3:42 AM
John Wells
John Wells - avatar