Question: That's my script where I created the mess in the else if:

```
$( window ).on('load resize', function(){
    var $sidebar   = $(".sidebar_container"), 
        $window    = $(window),
        offset     = $sidebar.offset(),
        topPadding = 130;

    $window.scroll(function() {
        if (($window.scrollTop() > offset.top) && (window.matchMedia('(min-width: 1200px)').matches)) {
            $sidebar.stop().animate({
                marginTop: $window.scrollTop() - offset.top + topPadding
            });
        } else if (($window.scrollTop() + offset.top + $(".sidebar_container").height()) > ($window.scrollTop() + $(".main-footer").height())){
            $sidebar.stop().animate({
                marginTop: $window.scrollTop() - offset.top - $(".main-footer").height()
            });
        }else{
            $sidebar.stop().animate({
                marginTop: 0
            });
        }

    });
});

```

Answer: 
The `newResult` list is empty, you cannot use `newResult[index] = element` to add new elements to it. Use `newResult += element` or `newResult.add(emenent)` instead.
You are actually trying to access the index of the array while you have not initialized any element to it.
Initialize like this newResult.add(i)