mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 03:17:49 +00:00
Use _.clamp in _.sampleSize, _.endsWith, and _.startsWith.
This commit is contained in:
@@ -7349,7 +7349,7 @@
|
|||||||
length = result.length,
|
length = result.length,
|
||||||
lastIndex = length - 1;
|
lastIndex = length - 1;
|
||||||
|
|
||||||
n = nativeMin(nativeMax(toInteger(n), 0), length);
|
n = clamp(toInteger(n), 0, length);
|
||||||
while (++index < n) {
|
while (++index < n) {
|
||||||
var rand = baseRandom(index, lastIndex),
|
var rand = baseRandom(index, lastIndex),
|
||||||
value = result[rand];
|
value = result[rand];
|
||||||
@@ -11134,7 +11134,7 @@
|
|||||||
var length = string.length;
|
var length = string.length;
|
||||||
position = position === undefined
|
position = position === undefined
|
||||||
? length
|
? length
|
||||||
: nativeMin(nativeMax(toInteger(position), 0), length);
|
: clamp(toInteger(position), 0, length);
|
||||||
|
|
||||||
position -= target.length;
|
position -= target.length;
|
||||||
return position >= 0 && string.indexOf(target, position) == position;
|
return position >= 0 && string.indexOf(target, position) == position;
|
||||||
@@ -11518,7 +11518,7 @@
|
|||||||
*/
|
*/
|
||||||
function startsWith(string, target, position) {
|
function startsWith(string, target, position) {
|
||||||
string = toString(string);
|
string = toString(string);
|
||||||
position = nativeMin(nativeMax(toInteger(position), 0), string.length);
|
position = clamp(toInteger(position), 0, string.length);
|
||||||
return string.lastIndexOf(target, position) == position;
|
return string.lastIndexOf(target, position) == position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user