Get the first element from an iterable.
Time complexity: O(1)
Space complexity: O(1)
The iterable to take elements from
Optional
The first element of the iterable
Iterable
first([1, 2, 3]); // 1 Copy
first([1, 2, 3]); // 1
Get the first n elements from an iterable.
n
Time complexity: O(n)
Space complexity: O(n)
The number of elements to take from the iterable
The first take elements of the iterable
take
[...first([1, 2, 3], 1)]; // [1] Copy
[...first([1, 2, 3], 1)]; // [1]
[...first([1, 2, 3], 2)]; // [1, 2] Copy
[...first([1, 2, 3], 2)]; // [1, 2]
Get the first element from an iterable.
Time complexity: O(1)
Space complexity: O(1)