Let\'s suppose I wanted a sort function that returns a sorted copy of the inputted array. I naively tried this
function sort(arr) { return arr.sort(); } >
Try the following
function sortCopy(arr) { return arr.slice(0).sort(); }
The slice(0) expression creates a copy of the array starting at element 0.
slice(0)