I have built a function that returns `"YES"` or `"NO"` based on some input.
The input is a string of brackets that should be balanced.

Example:

Balanced - { [ ( ) ] }  

 Non-balanced - { [ ( ] ) }

The function is returning `undefined` for this call. 

> 
> isBalanced('{[(])}');
> 
> 
> 

Tired of debugging. I am sure there is something wrong inside the loop. 

```
function isBalanced(s) {
    let brackets = s.split('');
    let balanced = "YES";
    const closedBrackets = ')]}';
    const bracketCompliment = {
        '(' : ')',
        '[' : ']',
        '{' : '}'
    };
    for(let idx = 0; idx < brackets.length; idx++){
        const item = brackets.splice(0, 1)[0];
        if(closedBrackets.includes(item)){
            balanced = "NO";   
            return;
        }
        const closeIdx = brackets.indexOf(bracketCompliment[item]);
        const remainder = closeIdx % 2;
        if(closeIdx === -1 || remainder !== 0){
            balanced = "NO";
            return;
        } else{
            brackets.splice(closeIdx, 1);
        }
    }
    return balanced;
}

```