Ensure _.sample handles falsey collection arguments.

This commit is contained in:
John-David Dalton
2013-09-08 15:09:09 -06:00
parent 0f9687ce62
commit 8c07a67fe9

View File

@@ -3895,7 +3895,7 @@
collection = collection.split(''); collection = collection.split('');
} }
if (n == null || guard) { if (n == null || guard) {
return collection[random(length - 1)]; return collection ? collection[random(length - 1)] : undefined;
} }
var result = shuffle(collection); var result = shuffle(collection);
result.length = nativeMin(nativeMax(0, n), result.length); result.length = nativeMin(nativeMax(0, n), result.length);