JSFiddle - React, Tailwind, and code Playground

by cvalleskey

HTML

<p><input id="in" value="" /><input type="button" id="go" value="Test" /></p>
<p id="out"></p>

JavaScript

function levels(str) {
       return str.replace(/\(/gi, "").length == str.replace(/\)/gi, "").length &&
           str.replace(/\[/gi, "").length == str.replace(/\]/gi, "").length &&
           str.replace(/\{/gi, "").length == str.replace(/\}/gi, "").length;
}

document.getElementById('go').onclick = function(e) {
    document.getElementById('out').innerText = levels(document.getElementById('in').value);
}