Javascript String checkBrackets(str)

Description

Javascript String checkBrackets(str)


function checkBrackets(str) {
  var opens = str.match(/\(/g) || [],
    closes = str.match(/\)/g) || [];//from   w ww .j a v  a2s  .  co  m
  return opens.length === closes.length;
}

Array.prototype.forEach.call(document.getElementsByTagName('li'), function(li) {
  li.classList.add(checkBrackets(li.textContent) ? 'valid' : 'invalid');
});



PreviousNext

Related