mirror of
https://github.com/swc-project/swc.git
synced 2024-12-22 13:11:31 +03:00
34 lines
1.0 KiB
TypeScript
34 lines
1.0 KiB
TypeScript
|
// Loaded from https://deno.land/x/ramda@v0.27.2/source/takeLast.js
|
||
|
|
||
|
|
||
|
import _curry2 from './internal/_curry2.js';
|
||
|
import drop from './drop.js';
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Returns a new list containing the last `n` elements of the given list.
|
||
|
* If `n > list.length`, returns a list of `list.length` elements.
|
||
|
*
|
||
|
* @func
|
||
|
* @memberOf R
|
||
|
* @since v0.16.0
|
||
|
* @category List
|
||
|
* @sig Number -> [a] -> [a]
|
||
|
* @sig Number -> String -> String
|
||
|
* @param {Number} n The number of elements to return.
|
||
|
* @param {Array} xs The collection to consider.
|
||
|
* @return {Array}
|
||
|
* @see R.dropLast
|
||
|
* @example
|
||
|
*
|
||
|
* R.takeLast(1, ['foo', 'bar', 'baz']); //=> ['baz']
|
||
|
* R.takeLast(2, ['foo', 'bar', 'baz']); //=> ['bar', 'baz']
|
||
|
* R.takeLast(3, ['foo', 'bar', 'baz']); //=> ['foo', 'bar', 'baz']
|
||
|
* R.takeLast(4, ['foo', 'bar', 'baz']); //=> ['foo', 'bar', 'baz']
|
||
|
* R.takeLast(3, 'ramda'); //=> 'mda'
|
||
|
*/
|
||
|
var takeLast = _curry2(function takeLast(n, xs) {
|
||
|
return drop(n >= 0 ? xs.length - n : 0, xs);
|
||
|
});
|
||
|
export default takeLast;
|