Skip to content

Instantly share code, notes, and snippets.

@BartlomiejSkwira
Created August 31, 2013 11:36
Show Gist options
  • Select an option

  • Save BartlomiejSkwira/6397696 to your computer and use it in GitHub Desktop.

Select an option

Save BartlomiejSkwira/6397696 to your computer and use it in GitHub Desktop.
Ends with
String::endsWith = (suffix) ->
@indexOf(suffix, @length - suffix.length) isnt -1
#Doesn't create a substring
#Uses native indexOf function for fastest results
#Skip unnecessary comparisons using the second parameter of indexOf to skip ahead
#Works in Internet Explorer
#NO Regex complications
#String.prototype.endsWith = function(suffix) {
# return this.indexOf(suffix, this.length - suffix.length) !== -1;
#};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment