Add _.rangeRight docs. [ci skip]

This commit is contained in:
John-David Dalton
2015-12-03 17:59:46 -08:00
parent 1cbb6f1405
commit 81e39f7c4b

View File

@@ -1517,10 +1517,10 @@
* `methodOf`, `mixin`, `modArgs`, `modArgsSet', `negate`, `nthArg`, `omit`,
* `omitBy`, `once`, `over`, `overEvery`, `overSome`, `partial`, `partialRight`,
* `partition`, `pick`, `pickBy`, `plant`, `property`, `propertyOf`, `pull`,
* `pullAll`, `pullAllBy`, `pullAt`, `push`, `range`, `rearg`, `reject`,
* `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
* `slice`, `sort`, `sortBy`, `sortByOrder`, `splice`, `spread`, `tail`,
* `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, `throttle`,
* `pullAll`, `pullAllBy`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`,
* `reject`, `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`,
* `shuffle`, `slice`, `sort`, `sortBy`, `sortByOrder`, `splice`, `spread`,
* `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, `throttle`,
* `thru`, `toArray`, `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`,
* `transform`, `unary`, `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`,
* `uniqWith`, `unset`, `unshift`, `unzip`, `unzipWith`, `values`, `valuesIn`,
@@ -3247,6 +3247,16 @@
return min + nativeFloor(nativeRandom() * (max - min + 1));
}
/**
* The base implementation of `_.range` and `_.rangeRight`.
*
* @private
* @param {number} [start=0] The start of the range.
* @param {number} end The end of the range.
* @param {number} [step=1] The value to increment or decrement by.
* @param {boolean} [fromRight] Specify iterating from right to left.
* @returns {Array} Returns the new array of numbers.
*/
function baseRange(start, end, step, fromRight) {
start = toNumber(start);
start = start === start ? start : 0;
@@ -3268,7 +3278,7 @@
result[index] = (end -= step);
} else {
result[index] = start;
start+= step;
start += step;
}
}
return result;
@@ -7599,8 +7609,8 @@
*
* The guarded methods are:
* `ary`, `curry`, `curryRight`, `drop`, `dropRight`, `every`, `fill`,
* `invert`, `parseInt`, `random`, `range`, `slice`, `some`, `sortBy`,
* `take`, `takeRight`, `template`, `trim`, `trimEnd`, `trimStart`,
* `invert`, `parseInt`, `random`, `range`, `rangeRight`, `slice`, `some`,
* `sortBy`, `take`, `takeRight`, `template`, `trim`, `trimEnd`, `trimStart`,
* and `words`
*
* @static
@@ -13309,6 +13319,40 @@
return baseRange(start, end, step);
}
/**
* This method is like `_.range` except that it populates values in
* descending order.
*
* @static
* @memberOf _
* @category Utility
* @param {number} [start=0] The start of the range.
* @param {number} end The end of the range.
* @param {number} [step=1] The value to increment or decrement by.
* @returns {Array} Returns the new array of numbers.
* @example
*
* _.rangeRight(4);
* // => [3, 2, 1, 0]
*
* _.rangeRight(-4);
* // => [-3, -2, -1, 0]
*
* _.rangeRight(1, 5);
* // => [4, 3, 2, 1]
*
* _.rangeRight(0, 20, 5);
* // => [15, 10, 5, 0]
*
* _.rangeRight(0, -4, -1);
* // => [-3, -2, -1, 0]
*
* _.rangeRight(1, 4, 0);
* // => [4, 4, 4]
*
* _.rangeRight(0);
* // => []
*/
function rangeRight(start, end, step) {
if (step && isIterateeCall(start, end, step)) {
end = step = undefined;