Tell us what’s happening:
I am lost as to the functional programming method for this challenge. I have tried it separately in a browser console and my solution works and sort is acting on a new array.
The solution given by the hint has concat and the sort function acts directly on the arr that is passed into the function.
My issue is that my solution, the given solution, and just straight up “return arr.sort()” all do not effect the globalArray variable. It returns the unsorted array each time.
I want to know what this challenge is trying to teach, and why concat, because I cannot figure it out.
Your code so far
var globalArray = [5, 6, 3, 2, 9];
function nonMutatingSort(arr) {
// Add your code below this line
var newArr = arr;
return newArr.sort();
// Add your code above this line
}
nonMutatingSort(globalArray);
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/functional-programming/return-a-sorted-array-without-changing-the-original-array