Merge pull request #5914 from chrootsu/lodash-takeRight

lodash: added _.takeRight() method
This commit is contained in:
Masahiro Wakame
2015-09-20 21:50:09 +09:00
2 changed files with 44 additions and 0 deletions

View File

@@ -428,6 +428,21 @@ result = <number>_.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function
return this.wordToNumber[word];
}, sortedIndexDict);
// _.takeRight
{
let testTakeRightArray: TResult[];
let testTakeRightList: _.List<TResult>;
let result: TResult[];
result = _.takeRight<TResult>(testTakeRightArray);
result = _.takeRight<TResult>(testTakeRightArray, 42);
result = _.takeRight<TResult>(testTakeRightList);
result = _.takeRight<TResult>(testTakeRightList, 42);
result = _(testTakeRightArray).takeRight().value();
result = _(testTakeRightArray).takeRight(42).value();
result = _(testTakeRightList).takeRight<TResult>().value();
result = _(testTakeRightList).takeRight<TResult>(42).value();
}
result = <number[]>_.union([1, 2, 3], [101, 2, 1, 10], [2, 1]);
result = <number[]>_([1, 2, 3]).union([101, 2, 1, 10], [2, 1]).value();

29
lodash/lodash.d.ts vendored
View File

@@ -1442,6 +1442,35 @@ declare module _ {
whereValue: W): number;
}
//_.takeRight
interface LoDashStatic {
/**
* Creates a slice of array with n elements taken from the end.
*
* @param array The array to query.
* @param n The number of elements to take.
* @return Returns the slice of array.
*/
takeRight<T>(
array: T[]|List<T>,
n?: number
): T[];
}
interface LoDashArrayWrapper<T> {
/**
* @see _.takeRight
*/
takeRight(n?: number): LoDashArrayWrapper<T>;
}
interface LoDashObjectWrapper<T> {
/**
* @see _.takeRight
*/
takeRight<TResult>(n?: number): LoDashArrayWrapper<TResult>;
}
//_.union
interface LoDashStatic {
/**