mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 02:47:50 +00:00
Cleanup support for a step of 0 in _.range and add unit tests.
Former-commit-id: 383719999d8f4a7e153784aea3b6f4174684dd9a
This commit is contained in:
6
build.js
6
build.js
@@ -3821,6 +3821,12 @@
|
|||||||
.replace(/(\n *)}/, ",$1 '/': '/'$1}");
|
.replace(/(\n *)}/, ",$1 '/': '/'$1}");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
// remove support for a `step` of `0` in `_.range`
|
||||||
|
if (!isLodash('range')) {
|
||||||
|
source = source.replace(matchFunction(source, 'range'), function(match) {
|
||||||
|
return match.replace(/typeof *step[^:]+:/, '+step ||');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// replace `slice` with `nativeSlice.call`
|
// replace `slice` with `nativeSlice.call`
|
||||||
_.each(['clone', 'first', 'initial', 'last', 'rest', 'toArray'], function(funcName) {
|
_.each(['clone', 'first', 'initial', 'last', 'rest', 'toArray'], function(funcName) {
|
||||||
|
|||||||
@@ -4682,12 +4682,15 @@
|
|||||||
* _.range(0, -10, -1);
|
* _.range(0, -10, -1);
|
||||||
* // => [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
|
* // => [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
|
||||||
*
|
*
|
||||||
|
* _.range(1, 4, 0);
|
||||||
|
* // => [1, 1, 1]
|
||||||
|
*
|
||||||
* _.range(0);
|
* _.range(0);
|
||||||
* // => []
|
* // => []
|
||||||
*/
|
*/
|
||||||
function range(start, end, step) {
|
function range(start, end, step) {
|
||||||
start = +start || 0;
|
start = +start || 0;
|
||||||
step = isNumber(step) ? step : 1;
|
step = typeof step == 'number' ? step : 1;
|
||||||
|
|
||||||
if (end == null) {
|
if (end == null) {
|
||||||
end = start;
|
end = start;
|
||||||
|
|||||||
@@ -1089,6 +1089,7 @@
|
|||||||
actual = lodash.pick(object, function(value) { return value != 3; });
|
actual = lodash.pick(object, function(value) { return value != 3; });
|
||||||
deepEqual(_.keys(actual), [], '_.pick should not accept a `callback`: ' + basename);
|
deepEqual(_.keys(actual), [], '_.pick should not accept a `callback`: ' + basename);
|
||||||
|
|
||||||
|
deepEqual(lodash.range(1, 4, 0), [1, 2, 3], '_.range should not support a `step` of `0`');
|
||||||
strictEqual(lodash.some([false, true, false]), true, '_.some: ' + basename);
|
strictEqual(lodash.some([false, true, false]), true, '_.some: ' + basename);
|
||||||
deepEqual(lodash.times(null, function() {}), [null], '_.times should not coerce `n` to a number: ' + basename);
|
deepEqual(lodash.times(null, function() {}), [null], '_.times should not coerce `n` to a number: ' + basename);
|
||||||
equal(lodash.template('${a}', object), '${a}', '_.template should ignore ES6 delimiters: ' + basename);
|
equal(lodash.template('${a}', object), '${a}', '_.template should ignore ES6 delimiters: ' + basename);
|
||||||
|
|||||||
@@ -2785,6 +2785,10 @@
|
|||||||
var actual = [func('0',1), func('1'), func(0, 1, '1')];
|
var actual = [func('0',1), func('1'), func(0, 1, '1')];
|
||||||
deepEqual(actual, [[0], [0], [0]]);
|
deepEqual(actual, [[0], [0], [0]]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should support a `step` of `0`', function() {
|
||||||
|
deepEqual(_.range(1, 4, 0), [1, 1, 1]);
|
||||||
|
});
|
||||||
}());
|
}());
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|||||||
Reference in New Issue
Block a user