Use String#slice instead of String#indexOf for _.endsWith and _.startsWith.

This commit is contained in:
John-David Dalton
2016-07-24 08:29:39 -07:00
parent 6a41a79ded
commit 6402af7db9
2 changed files with 15 additions and 18 deletions

View File

@@ -13703,8 +13703,9 @@
? length
: baseClamp(toInteger(position), 0, length);
var end = position;
position -= target.length;
return position >= 0 && string.indexOf(target, position) == position;
return position >= 0 && string.slice(position, end) == target;
}
/**
@@ -14152,7 +14153,8 @@
function startsWith(string, target, position) {
string = toString(string);
position = baseClamp(toInteger(position), 0, string.length);
return string.lastIndexOf(baseToString(target), position) == position;
target = baseToString(target);
return string.slice(position, position + target.length) == target;
}
/**