Created
September 16, 2013 09:44
-
-
Save gasolin/6578631 to your computer and use it in GitHub Desktop.
trim string (Levithan version)
This file contains 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
function trim(text) { | |
text.replace(/^\s+/, "");//.replace(/\s+$/, ""); | |
for (var i = text.length - 1; i >= 0; i--) { | |
if (/\s/.test(text.charAt(i))) { | |
text = text.substring(0, i + 1); | |
break; | |
} | |
} | |
return text; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment