Sorted Array, extra space in result

Tell us what’s happening:

Why do I keep getting a space before the 1st element in the resultant array? And how do I fix it?

Your code so far


var globalArray = [5, 6, 3, 2, 9];
function nonMutatingSort(arr) {
  // Add your code below this line
  return [].concat(arr).sort(function(a, b) {
    return a - b;
  });
  // Add your code above this line
}
nonMutatingSort(globalArray); //[ 2, 3, 5, 6, 9 ]

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 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

There is no extra space, if you mean this:

[ 2, 3, 5, 6, 9 ]

There is no extra space there. That’s just how the console chooses to visualize the array. If there were an extra space, it would look like:

[ " ", 2, 3, 5, 6, 9 ]

In that case, is there an issue with the challenge? Because it won’t accept my code.

Your code works for me.

Sometimes the browsers “glitch”. Try rebooting, try resetting the browser cache, try a different browser. One of those usually clears it up.