Last active
December 13, 2015 20:58
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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