8 kyu

Array#second

2,277 of 2,289Lordnibbler

Description:

Define a new instance method on the Array class called second, which returns the second item in an array (similar to the way .first and .last work in Ruby).

If there is no element with index 1 in the array, return nil.

Examples

[3, 4, 5].second  #  => 4 
[].second         #  => nil
Fundamentals
Arrays

Stats:

CreatedMay 9, 2014
PublishedMay 24, 2014
Warriors Trained3576
Total Skips166
Total Code Submissions9231
Total Times Completed2289
Ruby Completions2277
Total Stars29
% of votes with a positive feedback rating92% of 182
Total "Very Satisfied" Votes157
Total "Somewhat Satisfied" Votes20
Total "Not Satisfied" Votes5
Ad
Contributors
  • Lordnibbler Avatar
  • jhoffner Avatar
  • anter69 Avatar
  • Just4FunCoder Avatar
Ad