mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 02:17:50 +00:00
Ensure _.sample chains correctly.
This commit is contained in:
@@ -9587,11 +9587,12 @@
|
|||||||
lodash.sample = sample;
|
lodash.sample = sample;
|
||||||
|
|
||||||
lodash.prototype.sample = function(n, guard) {
|
lodash.prototype.sample = function(n, guard) {
|
||||||
if (!this.__chain__ && (n == null || guard)) {
|
n = guard ? null : n;
|
||||||
|
if (!this.__chain__ && n == null) {
|
||||||
return lodash.sample(this.value());
|
return lodash.sample(this.value());
|
||||||
}
|
}
|
||||||
return this.tap(function(value) {
|
return this.thru(function(value) {
|
||||||
lodash.sample(value);
|
return lodash.sample(value, n);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -9496,7 +9496,7 @@
|
|||||||
|
|
||||||
test('should return two random elements', 1, function() {
|
test('should return two random elements', 1, function() {
|
||||||
var actual = _.sample(array, 2);
|
var actual = _.sample(array, 2);
|
||||||
ok(actual[0] !== actual[1] && _.contains(array, actual[0]) && _.contains(array, actual[1]));
|
ok(actual.length == 2 && actual[0] !== actual[1] && _.contains(array, actual[0]) && _.contains(array, actual[1]));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should contain elements of the collection', 1, function() {
|
test('should contain elements of the collection', 1, function() {
|
||||||
@@ -9555,7 +9555,7 @@
|
|||||||
ok(_.contains(array, actual));
|
ok(_.contains(array, actual));
|
||||||
|
|
||||||
actual = _.sample(object, 2);
|
actual = _.sample(object, 2);
|
||||||
ok(actual[0] !== actual[1] && _.contains(array, actual[0]) && _.contains(array, actual[1]));
|
ok(actual.length == 2 && actual[0] !== actual[1] && _.contains(array, actual[0]) && _.contains(array, actual[1]));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should work when used as a callback for `_.map`', 2, function() {
|
test('should work when used as a callback for `_.map`', 2, function() {
|
||||||
@@ -9575,7 +9575,7 @@
|
|||||||
ok(wrapped instanceof _);
|
ok(wrapped instanceof _);
|
||||||
|
|
||||||
var actual = wrapped.value();
|
var actual = wrapped.value();
|
||||||
ok(actual[0] !== actual[1] && _.contains(array, actual[0]) && _.contains(array, actual[1]));
|
ok(actual.length == 2 && actual[0] !== actual[1] && _.contains(array, actual[0]) && _.contains(array, actual[1]));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
skipTest(2);
|
skipTest(2);
|
||||||
@@ -9602,7 +9602,7 @@
|
|||||||
ok(_.contains(collection, actual));
|
ok(_.contains(collection, actual));
|
||||||
|
|
||||||
actual = _.sample(collection, 2);
|
actual = _.sample(collection, 2);
|
||||||
ok(actual[0] !== actual[1] && _.contains(collection, actual[0]) && _.contains(collection, actual[1]));
|
ok(actual.length == 2 && actual[0] !== actual[1] && _.contains(collection, actual[0]) && _.contains(collection, actual[1]));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}());
|
}());
|
||||||
|
|||||||
Reference in New Issue
Block a user