mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-29 06:27:49 +00:00
Add findIndexFrom, findLastIndexFrom, indexOfFrom, & lastIndexOfFrom in FP.
This commit is contained in:
committed by
John-David Dalton
parent
64e765bf7a
commit
3d078383cb
@@ -84,8 +84,9 @@ exports.aryMethod = {
|
|||||||
],
|
],
|
||||||
'3': [
|
'3': [
|
||||||
'assignInWith', 'assignWith', 'clamp', 'differenceBy', 'differenceWith',
|
'assignInWith', 'assignWith', 'clamp', 'differenceBy', 'differenceWith',
|
||||||
'getOr', 'inRange', 'intersectionBy', 'intersectionWith', 'invokeArgs',
|
'findIndexFrom', 'findLastIndexFrom', 'getOr', 'indexOfFrom', 'inRange',
|
||||||
'invokeArgsMap', 'isEqualWith', 'isMatchWith', 'flatMapDepth', 'mergeWith',
|
'intersectionBy', 'intersectionWith', 'invokeArgs', 'invokeArgsMap',
|
||||||
|
'isEqualWith', 'isMatchWith', 'flatMapDepth', 'lastIndexOfFrom', 'mergeWith',
|
||||||
'orderBy', 'padChars', 'padCharsEnd', 'padCharsStart', 'pullAllBy',
|
'orderBy', 'padChars', 'padCharsEnd', 'padCharsStart', 'pullAllBy',
|
||||||
'pullAllWith', 'reduce', 'reduceRight', 'replace', 'set', 'slice',
|
'pullAllWith', 'reduce', 'reduceRight', 'replace', 'set', 'slice',
|
||||||
'sortedIndexBy', 'sortedLastIndexBy', 'transform', 'unionBy', 'unionWith',
|
'sortedIndexBy', 'sortedLastIndexBy', 'transform', 'unionBy', 'unionWith',
|
||||||
@@ -235,9 +236,13 @@ exports.realToAlias = (function() {
|
|||||||
exports.remap = {
|
exports.remap = {
|
||||||
'curryN': 'curry',
|
'curryN': 'curry',
|
||||||
'curryRightN': 'curryRight',
|
'curryRightN': 'curryRight',
|
||||||
|
'findIndexFrom': 'findIndex',
|
||||||
|
'findLastIndexFrom': 'findLastIndex',
|
||||||
'getOr': 'get',
|
'getOr': 'get',
|
||||||
|
'indexOfFrom': 'indexOf',
|
||||||
'invokeArgs': 'invoke',
|
'invokeArgs': 'invoke',
|
||||||
'invokeArgsMap': 'invokeMap',
|
'invokeArgsMap': 'invokeMap',
|
||||||
|
'lastIndexOfFrom': 'lastIndexOf',
|
||||||
'padChars': 'pad',
|
'padChars': 'pad',
|
||||||
'padCharsEnd': 'padEnd',
|
'padCharsEnd': 'padEnd',
|
||||||
'padCharsStart': 'padStart',
|
'padCharsStart': 'padStart',
|
||||||
|
|||||||
@@ -1097,6 +1097,47 @@
|
|||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
QUnit.module('fp.findIndexFrom methods');
|
||||||
|
|
||||||
|
var findIndexTestCases = {
|
||||||
|
'findIndexFrom': [
|
||||||
|
{ 'fromIndex': 0, 'expected': 1 },
|
||||||
|
{ 'fromIndex': 2, 'expected': 3 }
|
||||||
|
],
|
||||||
|
'findLastIndexFrom': [
|
||||||
|
{ 'fromIndex': -1, 'expected': 3 },
|
||||||
|
{ 'fromIndex': 2, 'expected': 1 }
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
_.forOwn(findIndexTestCases, function(testCases, methodName) {
|
||||||
|
QUnit.test('`fp.' + methodName + '` should have an argument order of `predicate`, `fromIndex` then `array`', function(assert) {
|
||||||
|
assert.expect(testCases.length);
|
||||||
|
|
||||||
|
var array = [100, 0, 100, 0];
|
||||||
|
|
||||||
|
_.each(testCases, function(testCase) {
|
||||||
|
assert.deepEqual(fp[methodName](fp.eq(0))(testCase.fromIndex)(array), testCase.expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
QUnit.test('`fp.' + methodName + '` should have its iteratee capped at 1 argument', function(assert) {
|
||||||
|
assert.expect(2);
|
||||||
|
|
||||||
|
var array = [100, 100];
|
||||||
|
|
||||||
|
var iteratee = function(value, index) {
|
||||||
|
assert.equal(value, 100);
|
||||||
|
assert.equal(index, undefined, 'iteratee is not capped');
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
fp[methodName](iteratee)(1)(array);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
QUnit.module('fp.flatMapDepth');
|
QUnit.module('fp.flatMapDepth');
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
@@ -1221,6 +1262,33 @@
|
|||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
QUnit.module('fp.indexOfFrom methods');
|
||||||
|
|
||||||
|
var indexOfTestCases = {
|
||||||
|
indexOfFrom: [
|
||||||
|
{fromIndex: 0, expected: 1},
|
||||||
|
{fromIndex: 2, expected: 3}
|
||||||
|
],
|
||||||
|
lastIndexOfFrom: [
|
||||||
|
{fromIndex: -1, expected: 3},
|
||||||
|
{fromIndex: 2, expected: 1}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
_.each(indexOfTestCases, function(testCases, methodName) {
|
||||||
|
QUnit.test('`fp.' + methodName + '` should have an argument order of `value`, `fromIndex` then `array`', function(assert) {
|
||||||
|
assert.expect(testCases.length);
|
||||||
|
|
||||||
|
var array = [100, 0, 100, 0];
|
||||||
|
|
||||||
|
_.each(testCases, function(testCase) {
|
||||||
|
assert.deepEqual(fp[methodName](0)(testCase.fromIndex)(array), testCase.expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
QUnit.module('fp.inRange');
|
QUnit.module('fp.inRange');
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user