Skip to content

Instantly share code, notes, and snippets.

@that4chanwolf
Created December 14, 2012 20:06
Show Gist options
  • Save that4chanwolf/4288219 to your computer and use it in GitHub Desktop.
Save that4chanwolf/4288219 to your computer and use it in GitHub Desktop.
String.autism() method Matches ticks `'`, quotes `"`, and parenthesis `(`.
String.prototype.autism = function () {
var parens = 0,
ticks = 0,
quotes = 0,
line = this.valueOf();
for (var i = 0; i < line.length; i++) {
if (line[i] === '(') { // Parens
parens++;
} else if (line[i] === ')') {
parens--;
}
if (line[i] === "'") { // Ticks
if (ticks % 2 === 0) { // Equal amoutnt of ticks
ticks++;
} else {
ticks--;
}
}
if (line[i] === '"') { // Quotes
if (quotes % 2 === 0) { // Equal amount of quotes
quotes++;
} else { // Odd amount of quotes
quotes--;
}
}
}
line = line +
Array(parens+1).join(')') +
Array(ticks+1).join("'") +
Array(quotes+1).join('"');
return line;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment