take
Summary
Returns a new list with only the first n elements from xs.
Tip
This function is curried.
Description
Takes the first n elements from xs and returns them in a new list of the same type.
An empty list of the same type is returned when n is either 0, NaN,
-Infinity or any other negative number. A full list (of the same type)
is returned when n is either Infinity or greater than the number of elements
in xs.
Examples
Works with arrays and objects.
1 2 3 4 5 6 7 | |
Parameters
| Name | Type | Description |
|---|---|---|
| n | number |
Number of elements to take. |
| xs | Array or Object |
List to take from. |
Return
Array or Object