Call .map for the first elements of the X array

I want to call .map only on the first X elements of the array. How to do it?

+6
source share
2 answers

In ruby ​​1.9

array.first(X).map{|e| ...} 

Ruby 1.8

 array[0, X].map{|e| ...} 
+11
source

Plain,

 array.first(X-number) 

and that's all.

See you...

-3
source

Source: https://habr.com/ru/post/887588/


All Articles