From d29d74f687ffedce432119b0c21f1234d97223ad Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 4 Oct 2016 20:21:07 -0700 Subject: [PATCH] Move `baseClamp` use to `arraySampleSize` and `baseSampleSize`. --- lodash.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lodash.js b/lodash.js index c9e47844c..67bacaca5 100644 --- a/lodash.js +++ b/lodash.js @@ -2433,7 +2433,7 @@ * @returns {Array} Returns the random elements. */ function arraySampleSize(array, n) { - return shuffleSelf(copyArray(array), n); + return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length)); } /** @@ -3940,7 +3940,8 @@ * @returns {Array} Returns the random elements. */ function baseSampleSize(collection, n) { - return shuffleSelf(values(collection), n); + var array = values(collection); + return shuffleSelf(array, baseClamp(n, 0, array.length)); } /** @@ -6612,7 +6613,7 @@ length = array.length, lastIndex = length - 1; - size = size === undefined ? length : baseClamp(size, 0, length); + size = size === undefined ? length : size; while (++index < size) { var rand = baseRandom(index, lastIndex), value = array[rand];