SERVER-8723 String.prototype.endsWith performance improvement

instead of RegExp, using lastIndexOf to calculate if string ends with
str.