mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 17:47:49 +00:00
Add createRange.
This commit is contained in:
59
lodash.js
59
lodash.js
@@ -4308,6 +4308,31 @@
|
|||||||
return wrapper;
|
return wrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a `_.range` or `_.rangeRight` function.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {boolean} [fromRight] Specify iterating from right to left.
|
||||||
|
* @returns {Function} Returns the new range function.
|
||||||
|
*/
|
||||||
|
function createRange(fromRight) {
|
||||||
|
return function(start, end, step) {
|
||||||
|
if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
|
||||||
|
end = step = undefined;
|
||||||
|
}
|
||||||
|
start = toNumber(start);
|
||||||
|
start = start === start ? start : 0;
|
||||||
|
if (end === undefined) {
|
||||||
|
end = start;
|
||||||
|
start = 0;
|
||||||
|
} else {
|
||||||
|
end = toNumber(end) || 0;
|
||||||
|
}
|
||||||
|
step = step === undefined ? (start < end ? 1 : -1) : (toNumber(step) || 0);
|
||||||
|
return baseRange(start, end, step, fromRight);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a function that wraps `func` to continue currying.
|
* Creates a function that wraps `func` to continue currying.
|
||||||
*
|
*
|
||||||
@@ -13441,22 +13466,7 @@
|
|||||||
* _.range(0);
|
* _.range(0);
|
||||||
* // => []
|
* // => []
|
||||||
*/
|
*/
|
||||||
function range(start, end, step) {
|
var range = createRange();
|
||||||
if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
|
|
||||||
end = step = undefined;
|
|
||||||
}
|
|
||||||
start = toNumber(start);
|
|
||||||
start = start === start ? start : 0;
|
|
||||||
|
|
||||||
if (end === undefined) {
|
|
||||||
end = start;
|
|
||||||
start = 0;
|
|
||||||
} else {
|
|
||||||
end = toNumber(end) || 0;
|
|
||||||
}
|
|
||||||
step = step === undefined ? (start < end ? 1 : -1) : (toNumber(step) || 0);
|
|
||||||
return baseRange(start, end, step);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is like `_.range` except that it populates values in
|
* This method is like `_.range` except that it populates values in
|
||||||
@@ -13492,22 +13502,7 @@
|
|||||||
* _.rangeRight(0);
|
* _.rangeRight(0);
|
||||||
* // => []
|
* // => []
|
||||||
*/
|
*/
|
||||||
function rangeRight(start, end, step) {
|
var rangeRight = createRange(true);
|
||||||
if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
|
|
||||||
end = step = undefined;
|
|
||||||
}
|
|
||||||
start = toNumber(start);
|
|
||||||
start = start === start ? start : 0;
|
|
||||||
|
|
||||||
if (end === undefined) {
|
|
||||||
end = start;
|
|
||||||
start = 0;
|
|
||||||
} else {
|
|
||||||
end = toNumber(end) || 0;
|
|
||||||
}
|
|
||||||
step = step === undefined ? (start < end ? 1 : -1) : (toNumber(step) || 0);
|
|
||||||
return baseRange(start, end, step, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invokes the iteratee function `n` times, returning an array of the results
|
* Invokes the iteratee function `n` times, returning an array of the results
|
||||||
|
|||||||
Reference in New Issue
Block a user