Skip to content

Instantly share code, notes, and snippets.

@eckdanny
Created June 5, 2014 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eckdanny/d931a92dc410ae7f02f9 to your computer and use it in GitHub Desktop.
Save eckdanny/d931a92dc410ae7f02f9 to your computer and use it in GitHub Desktop.
Forehead slapper after code challenge
'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