For example:
I have a string only contains brackets '(' and ')'. How to count missing brackets?

My code:

```
var str = '(())';
var open = 0, close = 0, count = 0;
for (var i = 0; i < str.length; i++) {
  if (str[i] == '(') {
    open++;
    count = Math.abs(open - close);
  } else {
    close++;
    count = Math.abs(open - close);
  }
}
console.log(count);

```

Input: '(())'
Output: 0

Input: '(()'
Output: 1

Input: '))(('
Output: 4

Input: '(()('
Output: 2

Input: '(()()))(())(())'
Output: 1