Skip to content

Instantly share code, notes, and snippets.

@alassek
Created August 21, 2009 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alassek/172271 to your computer and use it in GitHub Desktop.
Save alassek/172271 to your computer and use it in GitHub Desktop.
// http://blog.stevenlevithan.com/archives/faster-trim-javascript
function trim12 (str) {
var str = str.replace(/^\s\s*/, ''),
ws = /\s/,
i = str.length;
while (ws.test(str.charAt(--i)));
return str.slice(0, i + 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment