Created
March 17, 2014 19:01
-
-
Save JesterMan/9605985 to your computer and use it in GitHub Desktop.
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
<head></head> | |
<body> | |
<script> | |
var expressions = [ ")(){}", "[]({})", "([])", "{()[]}", "([)]" ]; | |
function expTest(){ | |
var brackTest = function(x, z){ | |
for (var k = 1 +z; k < testInput.length; k++) { | |
if (testInput[k] == x){ | |
testInput.splice(z,1); | |
k--; | |
testInput.splice(k,1); | |
formatScore--; | |
j=-1; | |
k=k-z; | |
// on the fourth element in expressions (i.e. "{()[]}"), when it is trimmed down to "{[]}", the k=k-z line does not appear to work. k = 1, z=1, but at the start of the next iteration, k=2 | |
return; | |
} | |
else if (testInput[k] =='{'){ | |
brackTest('}', k); | |
} | |
else if (testInput[k]=='['){ | |
brackTest(']', k); | |
} | |
else if (testInput[k]=='('){ | |
brackTest(')', k); | |
} | |
else { | |
debugger | |
console.log('0'+'\n') | |
k = testInput.length, | |
j = testInput.length; | |
} | |
}; | |
}; | |
for (var i =0; i < expressions.length; i++) { | |
var formatScore = expressions[i].length/2; | |
var testInput = expressions[i].split(''); | |
if (testInput.length%2 == 1){ | |
console.log('0'+'\n'); | |
} else { | |
for (var j=0; j < testInput.length; j++){ | |
if (testInput[j] =='{'){ | |
brackTest('}', j); | |
}else if (testInput[j]=='['){ | |
brackTest(']', j); | |
}else if (testInput[j]=='('){ | |
brackTest(')', j); | |
} | |
if (testInput.length==0){ | |
if (formatScore==0){ | |
console.log('1'+'\n'); | |
}else{ | |
debugger | |
console.log('0'+'\n'); | |
} | |
} | |
} | |
}; | |
}; | |
}; | |
expTest(); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment