Skip to content

Commit ddbffe1

Browse files
committed
Merge pull request DefinitelyTyped#5914 from chrootsu/lodash-takeRight
lodash: added _.takeRight() method
2 parents 755307e + e0bd145 commit ddbffe1

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

lodash/lodash-tests.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,21 @@ result = <number>_.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function
428428
return this.wordToNumber[word];
429429
}, sortedIndexDict);
430430

431+
// _.takeRight
432+
{
433+
let testTakeRightArray: TResult[];
434+
let testTakeRightList: _.List<TResult>;
435+
let result: TResult[];
436+
result = _.takeRight<TResult>(testTakeRightArray);
437+
result = _.takeRight<TResult>(testTakeRightArray, 42);
438+
result = _.takeRight<TResult>(testTakeRightList);
439+
result = _.takeRight<TResult>(testTakeRightList, 42);
440+
result = _(testTakeRightArray).takeRight().value();
441+
result = _(testTakeRightArray).takeRight(42).value();
442+
result = _(testTakeRightList).takeRight<TResult>().value();
443+
result = _(testTakeRightList).takeRight<TResult>(42).value();
444+
}
445+
431446
result = <number[]>_.union([1, 2, 3], [101, 2, 1, 10], [2, 1]);
432447

433448
result = <number[]>_([1, 2, 3]).union([101, 2, 1, 10], [2, 1]).value();

lodash/lodash.d.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,35 @@ declare module _ {
14421442
whereValue: W): number;
14431443
}
14441444

1445+
//_.takeRight
1446+
interface LoDashStatic {
1447+
/**
1448+
* Creates a slice of array with n elements taken from the end.
1449+
*
1450+
* @param array The array to query.
1451+
* @param n The number of elements to take.
1452+
* @return Returns the slice of array.
1453+
*/
1454+
takeRight<T>(
1455+
array: T[]|List<T>,
1456+
n?: number
1457+
): T[];
1458+
}
1459+
1460+
interface LoDashArrayWrapper<T> {
1461+
/**
1462+
* @see _.takeRight
1463+
*/
1464+
takeRight(n?: number): LoDashArrayWrapper<T>;
1465+
}
1466+
1467+
interface LoDashObjectWrapper<T> {
1468+
/**
1469+
* @see _.takeRight
1470+
*/
1471+
takeRight<TResult>(n?: number): LoDashArrayWrapper<TResult>;
1472+
}
1473+
14451474
//_.union
14461475
interface LoDashStatic {
14471476
/**

0 commit comments

Comments
 (0)