Bump to v3.9.2.

This commit is contained in:
jdalton
2015-05-24 01:44:03 -07:00
parent b6f9660ab0
commit 314048b069
23 changed files with 169 additions and 92 deletions

View File

@@ -1,6 +1,6 @@
var baseRandom = require('../internal/baseRandom'),
isIterateeCall = require('../internal/isIterateeCall'),
shuffle = require('./shuffle'),
toArray = require('../lang/toArray'),
toIterable = require('../internal/toIterable');
/* Native method references for those with the same name as other `lodash` methods. */
@@ -30,8 +30,20 @@ function sample(collection, n, guard) {
var length = collection.length;
return length > 0 ? collection[baseRandom(0, length - 1)] : undefined;
}
var result = shuffle(collection);
result.length = nativeMin(n < 0 ? 0 : (+n || 0), result.length);
var index = -1,
result = toArray(collection),
length = result.length,
lastIndex = length - 1;
n = nativeMin(n < 0 ? 0 : (+n || 0), length);
while (++index < n) {
var rand = baseRandom(index, lastIndex),
value = result[rand];
result[rand] = result[index];
result[index] = value;
}
result.length = n;
return result;
}