"should not be hard coded" test failure

Tell us what’s happening:
My solution to the non-mutating sort challenge seems to pass all the tests but for the requirement "nonMutatingSort(globalArray) should not be hard coded".
As can be seen from my code, below, nothing in my nonMutatingSort function references that global variable directly. So I fail to understand why this test returns an error when nothing is actually hard coded.
Could anyone please clarify what this “should not be hard coded” test actually checks?

Your code so far

var globalArray = [5, 6, 3, 2, 9];

function nonMutatingSort(arr) {
// Only change code below this line
  return arr.slice(0).sort((val1, val2) => (val1 - val2));
// Only change code above this line


Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0

Challenge: Return a Sorted Array Without Changing the Original Array

Link to the challenge:

That’s a bug with the regex in the test. It is matching on your parameters for the sort method. If you change the params to a and b your code will pass.

The test:


Edit: I opened an issue.

Thanks. This information helped.
My fault or being so descriptive with my variable names :wink:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.