Sliding Window Algorithm Leetcode Javascript