Created
December 14, 2012 20:06
-
-
Save that4chanwolf/4288219 to your computer and use it in GitHub Desktop.
String.autism() method Matches ticks `'`, quotes `"`, and parenthesis `(`.
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
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