Skip to content

Instantly share code, notes, and snippets.

@frostney
Last active December 13, 2015 20:58
Show Gist options
  • Save frostney/4973597 to your computer and use it in GitHub Desktop.
Save frostney/4973597 to your computer and use it in GitHub Desktop.
ES6-like string functions (they are not really compatible - like not at all - to the official specification though)
do (String) ->
String::contains or= (searchString, position = 0) -> @toString().indexOf(searchString) >= position
String::startsWith or= (searchString, position = 0) -> @toString.toString().indexOf(searchString) >= position
String::endsWith or= (searchString, position = @length) -> @toString().lastIndexOf(searchString) is position - searchString.length
String::repeat or= (count) ->
newString = ''
newString += @toString() for [1..count]
newString
String::toArray or= -> @toString().split ''
String::reverse or= -> @toArray().reverse().join ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment