I'm confusing about it... a > b == a - b?

Hi everyone, i has been realised js algorithms and data structures course, and in the module of Functional progamming, more in concrete the exercise “Return a Sorted Array Without Changing the Original Array” i was found a solution like =>

function nonMutatingSort(arr) {
  return arr.slice().sort(function(a,b) {
    return a < b
  })} 

it didn’t passed the tests but i test it in my local pc, and it returns every array what it should throw in the right way, so , if it returns the rights array and checks don’t pass, what’s wrong with it? (The other test like, it don’t modify the array , etc… it pass)
And the only way is changing the symbol “<” for “-”

I would read up a little more on the sort method, specifically what it expects the callback function to return.

Well, it makes sense but why it returns a correct array putting it to “<” ? , the test should be pass okay i mean, if you call the function let arr = nonMutatingSort(arr)
assert.equal(arr, arr_of_the_test) , they should be equally or not?

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