Skip to content

Instantly share code, notes, and snippets.

@gasolin
Created September 16, 2013 09:44
Show Gist options
  • Save gasolin/6578631 to your computer and use it in GitHub Desktop.
Save gasolin/6578631 to your computer and use it in GitHub Desktop.
trim string (Levithan version)
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