server-json/node_modules/ramda/es/nth.js
2024-11-01 08:00:42 +00:00

31 lines
No EOL
836 B
JavaScript

import _curry2 from "./internal/_curry2.js";
import _nth from "./internal/_nth.js";
/**
* Returns the nth element of the given list or string. If n is negative the
* element at index length + n is returned.
*
* @func
* @memberOf R
* @since v0.1.0
* @category List
* @sig Number -> [a] -> a | Undefined
* @sig Number -> String -> String | Undefined
* @param {Number} offset
* @param {*} list
* @return {*}
* @example
*
* const list = ['foo', 'bar', 'baz', 'quux'];
* R.nth(1, list); //=> 'bar'
* R.nth(-1, list); //=> 'quux'
* R.nth(-99, list); //=> undefined
*
* R.nth(2, 'abc'); //=> 'c'
* R.nth(3, 'abc'); //=> undefined
* @symb R.nth(-1, [a, b, c]) = c
* @symb R.nth(0, [a, b, c]) = a
* @symb R.nth(1, [a, b, c]) = b
*/
var nth = /*#__PURE__*/_curry2(_nth);
export default nth;