1 | var _curry2 =
|
---|
2 | /*#__PURE__*/
|
---|
3 | require("./internal/_curry2.js");
|
---|
4 |
|
---|
5 | var _isString =
|
---|
6 | /*#__PURE__*/
|
---|
7 | require("./internal/_isString.js");
|
---|
8 | /**
|
---|
9 | * Returns the nth element of the given list or string. If n is negative the
|
---|
10 | * element at index length + n is returned.
|
---|
11 | *
|
---|
12 | * @func
|
---|
13 | * @memberOf R
|
---|
14 | * @since v0.1.0
|
---|
15 | * @category List
|
---|
16 | * @sig Number -> [a] -> a | Undefined
|
---|
17 | * @sig Number -> String -> String
|
---|
18 | * @param {Number} offset
|
---|
19 | * @param {*} list
|
---|
20 | * @return {*}
|
---|
21 | * @example
|
---|
22 | *
|
---|
23 | * const list = ['foo', 'bar', 'baz', 'quux'];
|
---|
24 | * R.nth(1, list); //=> 'bar'
|
---|
25 | * R.nth(-1, list); //=> 'quux'
|
---|
26 | * R.nth(-99, list); //=> undefined
|
---|
27 | *
|
---|
28 | * R.nth(2, 'abc'); //=> 'c'
|
---|
29 | * R.nth(3, 'abc'); //=> ''
|
---|
30 | * @symb R.nth(-1, [a, b, c]) = c
|
---|
31 | * @symb R.nth(0, [a, b, c]) = a
|
---|
32 | * @symb R.nth(1, [a, b, c]) = b
|
---|
33 | */
|
---|
34 |
|
---|
35 |
|
---|
36 | var nth =
|
---|
37 | /*#__PURE__*/
|
---|
38 | _curry2(function nth(offset, list) {
|
---|
39 | var idx = offset < 0 ? list.length + offset : offset;
|
---|
40 | return _isString(list) ? list.charAt(idx) : list[idx];
|
---|
41 | });
|
---|
42 |
|
---|
43 | module.exports = nth; |
---|