Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Clear category for [old] Brackets by SaintDron
"use strict";
function brackets(expression){
let e = expression.replace(/[*+-/\d]/g, '');
while (e !== (e = e.replace(/\{\}|\(\)|\[\]/, ''))) {}
return !e;
}
var assert = require('assert');
if (!global.is_checking) {
assert.equal(brackets("((5+3)*2+1)"), true, "Simple");
assert.equal(brackets("{[(3+1)+2]+}"), true, "Different types");
assert.equal(brackets("(3+{1-1)}"), false, ") is alone inside {}");
assert.equal(brackets("[1+1]+(2*2)-{3/3}"), true, "Different operators");
assert.equal(brackets("(({[(((1)-2)+3)-3]/3}-3)"), false, "One is redundant");
assert.equal(brackets("2+3"), true, "No brackets, no problem");
console.log("Coding complete? Click 'Check' to review your tests and earn cool rewards!");
}
Feb. 16, 2019
Comments: