From 15a44fe6504e927d6308f8824cea1e495d55c189 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 24 Jul 2014 00:51:23 -0700 Subject: [PATCH] Make `_.random` and `_.range` work as callbacks to `_.map`. --- lodash.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lodash.js b/lodash.js index 80b0a1b53..0f01cfdb1 100644 --- a/lodash.js +++ b/lodash.js @@ -8927,6 +8927,10 @@ * // => a floating-point number between 1.2 and 5.2 */ function random(min, max, floating) { + // enables use as a callback for functions like `_.map` + if (floating && floating[max] === min) { + max = floating = null; + } var noMin = min == null, noMax = max == null; @@ -8992,6 +8996,11 @@ */ function range(start, end, step) { start = +start || 0; + + // enables use as a callback for functions like `_.map` + if (step && step[end] === start) { + end = step = null; + } step = step == null ? 1 : (+step || 0); if (end == null) {