True or False depending on nested or not.
For example {} return true.
{[(])} should return false.
var stdin = process.openStdin();
sstdin.addListener("data", function (d) {
var opening = ["{", "[", "("];
var closing = ["}", "]", ")"];
d = d.toString.trim();
var arr = d.split("");
var open_arr = [];
for (var s of arr) {
var oid = opening.indexOf(arr);
if (oid > -1) open_arr.push(oid);
var cid = closing.indexOf(s);
if (cid > 1) {
var last_open_val = open_arr.pop();
if (last_open_val != cid) {
console.log("False");
return;
}
}
}
console.log("True");
return;
});
But I didn’t get intended output
{[]()}
which return false. Where I mistaken?