forked from Tinkoff/utils.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslice.ts
More file actions
20 lines (18 loc) · 809 Bytes
/
slice.ts
File metadata and controls
20 lines (18 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { slice } from '../typings/types';
import curryN from '../function/curryN';
/**
* Returns the elements of the given list or string (or object with a `slice`
* method) from `fromIndex` (inclusive) to `toIndex` (exclusive).
*
* @param {Number} fromIndex The start index (inclusive).
* @param {Number} toIndex The end index (exclusive).
* @param {Array | String} list
* @return {Array | String}
* @example
*
* slice(1, 3, ['a', 'b', 'c', 'd']); //=> ['b', 'c']
* slice(1, Infinity, ['a', 'b', 'c', 'd']); //=> ['b', 'c', 'd']
* slice(0, -1, ['a', 'b', 'c', 'd']); //=> ['a', 'b', 'c']
* slice(-3, -1, ['a', 'b', 'c', 'd']); //=> ['b', 'c']
*/
export default curryN(3, (fromIndex, toIndex, list = []) => list.slice(fromIndex, toIndex)) as typeof slice