The question, as asked, is misleading. Arrays don't compare in Javascript! 🙂 Also, while the arr1 and arr2 values don't change, the arrays they refer to do, so the const is likely to trip some people up.
The .sort function returns the array that was sorted, so comparing arr1.sort() to arr1 is just comparing the array reference to itself. The same goes for arr2 on the next line (the use of == is another potential red herring, since the arrays are the same, so type conversion doesn't happen). Finally, while the sorted arrays contain the same info, arr1 is a different object to arr2, so the final comparison is false.
Sorry... my wording was probably unclear. I mean that it's a trick question. It has red herrings in it.
The misleading nature is where you state: "...in various sorting conditions?"
This misleads the reader since sorting is irrelevant here. The only real relevance is that the sort() method returns the original array object.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
The question, as asked, is misleading. Arrays don't compare in Javascript! 🙂 Also, while the arr1 and arr2 values don't change, the arrays they refer to do, so the
const
is likely to trip some people up.The
.sort
function returns the array that was sorted, so comparingarr1.sort()
toarr1
is just comparing the array reference to itself. The same goes forarr2
on the next line (the use of==
is another potential red herring, since the arrays are the same, so type conversion doesn't happen). Finally, while the sorted arrays contain the same info,arr1
is a different object toarr2
, so the final comparison is false.B
Which part of the question is misleading? Can you quote it here so I can fix it?
Sorry... my wording was probably unclear. I mean that it's a trick question. It has red herrings in it.
The misleading nature is where you state: "...in various sorting conditions?"
This misleads the reader since sorting is irrelevant here. The only real relevance is that the
sort()
method returns the original array object.