source: node_modules/ramda/es/takeLast.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 977 bytes
Line 
1import _curry2 from "./internal/_curry2.js";
2import drop from "./drop.js";
3/**
4 * Returns a new list containing the last `n` elements of the given list.
5 * If `n > list.length`, returns a list of `list.length` elements.
6 *
7 * @func
8 * @memberOf R
9 * @since v0.16.0
10 * @category List
11 * @sig Number -> [a] -> [a]
12 * @sig Number -> String -> String
13 * @param {Number} n The number of elements to return.
14 * @param {Array} xs The collection to consider.
15 * @return {Array}
16 * @see R.dropLast
17 * @example
18 *
19 * R.takeLast(1, ['foo', 'bar', 'baz']); //=> ['baz']
20 * R.takeLast(2, ['foo', 'bar', 'baz']); //=> ['bar', 'baz']
21 * R.takeLast(3, ['foo', 'bar', 'baz']); //=> ['foo', 'bar', 'baz']
22 * R.takeLast(4, ['foo', 'bar', 'baz']); //=> ['foo', 'bar', 'baz']
23 * R.takeLast(3, 'ramda'); //=> 'mda'
24 */
25
26var takeLast =
27/*#__PURE__*/
28_curry2(function takeLast(n, xs) {
29 return drop(n >= 0 ? xs.length - n : 0, xs);
30});
31
32export default takeLast;
Note: See TracBrowser for help on using the repository browser.