ruby on rails - Stuck on how to use .first and .last in a Array -


i need create method named first_and_last. take 1 argument - array - , return new array first , last objects.

my attempt:

def first_and_last(a)   first_and_last = [1,2,3]   first_and_last.last.first end 

here's confused, says need strings "a" , "d" along numbers. however, there 3 numbers , 4 strings. figured 0 .first of numbers.

describe "first_and_last"       "creates new array numbers"         expect( first_and_last([1,2,3]) ).to eq([1,3])       end       "creates new array strings"         expect( first_and_last(["a", "b", "c", "d"]) ).to eq(["a", "d"])       end     end 

i'm not getting how include both 1,2,3 , strings "a", "b", "c", "d" array while using .first , .last

thanks ahead of time help!

def first_and_last(array)   [array.first, array.last] end 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -