Created
June 5, 2014 22:24
-
-
Save eckdanny/d931a92dc410ae7f02f9 to your computer and use it in GitHub Desktop.
Forehead slapper after code challenge
This file contains hidden or 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
'use strict'; | |
var input = [ | |
'[[({}{})]{}]', | |
'][(}))(}})]', | |
'[(){}]', | |
']()', | |
'{([]{})()}' | |
] | |
, output = [1, 0, 1, 0, 1 ] | |
; | |
function isValid (arr) { | |
var reduce = function (str) { | |
var s = str; | |
s = s.replace(/\{\}/g, ''); | |
s = s.replace(/\[\]/g, ''); | |
s = s.replace(/\(\)/g, ''); | |
return s; | |
}; | |
var i, output = []; | |
var before | |
, after | |
, last | |
; | |
for (i in arr) { | |
last = arr[i]; | |
do { | |
before = last; | |
after = reduce(before); | |
last = after; | |
} while (before !== after); | |
output.push(after.length > 0); | |
} | |
return output; | |
} | |
console.log(output); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment