From 7acd3d52974cfa7ce6b70a84fff83724f985ae7a Mon Sep 17 00:00:00 2001 From: Stereokai Date: Sat, 3 Aug 2013 11:26:44 +0300 Subject: [PATCH] Enable _.range() to accept a 0 for step Enable `_.range()` to accept a `0` for `step`, for initializing arrays such as `[0, 0, 0, 0, 0]`, `[-1, -1, -1, -1, -1]`, useful in many use cases with inconsistent/morphing object arrays. Former-commit-id: 5a263ec17e454ba38dfa9b6deb913dddccaddfeb --- lodash.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lodash.js b/lodash.js index d8c999d9d..6faddc626 100644 --- a/lodash.js +++ b/lodash.js @@ -4687,7 +4687,7 @@ */ function range(start, end, step) { start = +start || 0; - step = +step || 1; + step = isNumber(step) ? step : 1; if (end == null) { end = start; @@ -4696,7 +4696,7 @@ // use `Array(length)` so engines, like Chakra and V8, avoid slower modes // http://youtu.be/XAqIpGU8ZZk#t=17m25s var index = -1, - length = nativeMax(0, ceil((end - start) / step)), + length = nativeMax(0, ceil((end - start) / (step || 1))), result = Array(length); while (++index < length) {