npm install bracket-balance --save
const bracketBalance = require('bracket-balance');
let exampleString = '{hello{{ ]}';
bracketBalance(exampleString, '{}');
//returns 2 because there are 2 more opening than closing brackets
String
to search throughString
containing a pair of brackets ('{}'
,'()'
or'[]'
)
Number
representing the difference between opening and closing brackets
- bigger than 0 means there are more opening than closing brackets
- exactly 0 means that there is an closing one for each opening bracket
- smaller than 0 means there are more closing than opening brackets