Leetcode Array Sorting Javascript