Javascript Copy And Sort Array Leetcode