From 9c8e1f4706ed8ff9c812d8751001bf8d5ca106e9 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 7 Oct 2012 18:43:20 -0700 Subject: [PATCH] Reduce `_.compact` and revert `_.random` use in `_.shuffle`. Former-commit-id: 17d153cb09c262830f1497f93c0f3d9b279c8f8a --- build.js | 2 +- lodash.js | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/build.js b/build.js index 9329ad03c..f7a38dd3d 100755 --- a/build.js +++ b/build.js @@ -138,7 +138,7 @@ 'reject': ['identity'], 'rest': [], 'result': ['isFunction'], - 'shuffle': ['random'], + 'shuffle': [], 'size': ['keys'], 'some': ['identity'], 'sortBy': ['identity'], diff --git a/lodash.js b/lodash.js index 5fd1d31a4..b1190f702 100644 --- a/lodash.js +++ b/lodash.js @@ -2396,8 +2396,9 @@ result = []; while (++index < length) { - if (array[index]) { - result.push(array[index]); + var value = array[index]; + if (value) { + result.push(value); } } return result; @@ -2860,7 +2861,7 @@ result = Array(length); while (++index < length) { - var rand = random(index); + var rand = nativeFloor(nativeRandom() * (index + 1)); result[index] = result[rand]; result[rand] = array[index]; }