Script – 23-27 Jan 30
I'm not understanding this kind of sorting
arr = arr.sort((a, b) => a < b ? 1 : -1);
What does 1, -1 mean?6 Replies
it sets the order of current value. More details here
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#description
-1 goes for
< 0
![](https://cdn.answeroverflow.com/937489865816297522/unknown.png)
This question has an answer! Thank you for helping 😄
If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/937489270631976970
if its for numbers you can just do
(a, b) => a - b
yh thats the one I'm familiar with
So I got confused when I saw the ternary with 1 and -1.
Thanks
This thread hasn’t had any activity in 12 hours, so it’s now locked.
Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/937489270631976970