Skip to content

Latest commit

 

History

History
13 lines (10 loc) · 279 Bytes

8 kyu - Enumerable Magic #25 - Take the First N Elements.md

File metadata and controls

13 lines (10 loc) · 279 Bytes

Task

Create a method take that accepts a list/array and a number n, and returns a list/array array of the first n elements from the list/array.

If you need help, here's a reference:

http://www.rubycuts.com/enum-take

Solution

def take list, n
  list[0...n]
end