Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4643

Return only the first and last items of an array in Ruby

$
0
0

I need to create a method named first_and_last. It should use one argument, an Array, and return a new Array with only the first and last objects of the argument.

Here is what I have so far, but the method seems to ignore the initial argument and just create a new array.

def first_and_last(a)  arr = Array.new  arr = ["a", "b", "c"]  end

Viewing all articles
Browse latest Browse all 4643

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>