Solve bracketValidator in JS