Skip to content

Instantly share code, notes, and snippets.

@michelle
Created December 20, 2012 18:33
Show Gist options
  • Save michelle/4347544 to your computer and use it in GitHub Desktop.
Save michelle/4347544 to your computer and use it in GitHub Desktop.
function strip_ends(str, ends) {
var special = { '[' : ']',
'(' : ')',
'<' : '>',
'{' : '}' };
if (str.charAt(0) == ends &&
(str.charAt(str.length - 1) == ends ||
str.charAt(str.length - 1) == special[ends])) {
str = str.slice(1, str.length - 1);
}
return str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment