Open kartamyshev opened 4 years ago
function getTheFirst (arr, n) {
if (!n) return arr[0];
return arr.reduce((newArr, current) => (arr.indexOf(current) < n) ? newArr.concat(current) : newArr, []);
}
function getTheFirst (arr, n) {
if (!n) return arr[0];
if (n < 0) return [];
return arr.slice(0, n);
}
function getTheFirst(arr, n) {
if (!n) return arr[0];
return arr.filter(current => arr.indexOf(current) < n);
}