From bd3fcab9c0262be3a3928a00cd139c67a475863f Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 18 Aug 2016 07:47:07 -0700 Subject: [PATCH] Add `fp.rangeStep` and `fp.rangeStepRight`. [closes #2584] --- fp/_mapping.js | 11 ++++++++--- test/test-fp.js | 28 +++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/fp/_mapping.js b/fp/_mapping.js index dd4abcb55..7fa8e672e 100644 --- a/fp/_mapping.js +++ b/fp/_mapping.js @@ -108,9 +108,10 @@ exports.aryMethod = { 'includesFrom', 'indexOfFrom', 'inRange', 'intersectionBy', 'intersectionWith', 'invokeArgs', 'invokeArgsMap', 'isEqualWith', 'isMatchWith', 'flatMapDepth', 'lastIndexOfFrom', 'mergeWith', 'orderBy', 'padChars', 'padCharsEnd', - 'padCharsStart', 'pullAllBy', 'pullAllWith', 'reduce', 'reduceRight', 'replace', - 'set', 'slice', 'sortedIndexBy', 'sortedLastIndexBy', 'transform', 'unionBy', - 'unionWith', 'update', 'xorBy', 'xorWith', 'zipWith' + 'padCharsStart', 'pullAllBy', 'pullAllWith', 'rangeStep', 'rangeStepRight', + 'reduce', 'reduceRight', 'replace', 'set', 'slice', 'sortedIndexBy', + 'sortedLastIndexBy', 'transform', 'unionBy', 'unionWith', 'update', 'xorBy', + 'xorWith', 'zipWith' ], '4': [ 'fill', 'setWith', 'updateWith' @@ -189,6 +190,8 @@ exports.methodRearg = { 'padCharsStart': [2, 1, 0], 'pullAllBy': [2, 1, 0], 'pullAllWith': [2, 1, 0], + 'rangeStep': [1, 2, 0], + 'rangeStepRight': [1, 2, 0], 'setWith': [3, 1, 2, 0], 'sortedIndexBy': [2, 1, 0], 'sortedLastIndexBy': [2, 1, 0], @@ -310,6 +313,8 @@ exports.remap = { 'padCharsEnd': 'padEnd', 'padCharsStart': 'padStart', 'propertyOf': 'get', + 'rangeStep': 'range', + 'rangeStepRight': 'rangeRight', 'restFrom': 'rest', 'spreadFrom': 'spread', 'trimChars': 'trim', diff --git a/test/test-fp.js b/test/test-fp.js index f06ac71c3..1e6509ab4 100644 --- a/test/test-fp.js +++ b/test/test-fp.js @@ -1783,15 +1783,33 @@ /*--------------------------------------------------------------------------*/ - QUnit.module('fp.range'); + QUnit.module('range methods'); - (function() { - QUnit.test('should have an argument order of `start` then `end`', function(assert) { + _.each(['range', 'rangeRight'], function(methodName) { + var func = fp[methodName], + isRange = methodName == 'range'; + + QUnit.test('`_.' + methodName + '` should have an argument order of `start` then `end`', function(assert) { assert.expect(1); - assert.deepEqual(fp.range(1)(4), [1, 2, 3]); + assert.deepEqual(func(1)(4), isRange ? [1, 2, 3] : [3, 2, 1]); }); - }()); + }); + + /*--------------------------------------------------------------------------*/ + + QUnit.module('rangeStep methods'); + + _.each(['rangeStep', 'rangeStepRight'], function(methodName) { + var func = fp[methodName], + isRange = methodName == 'rangeStep'; + + QUnit.test('`_.' + methodName + '` should have an argument order of `step`, `start`, then `end`', function(assert) { + assert.expect(1); + + assert.deepEqual(func(2)(1)(4), isRange ? [1, 3] : [3, 1]); + }); + }); /*--------------------------------------------------------------------------*/