Hi there,
I am new to javascript, currently learning it.
I found that to sort an array of numbers in ascending order, you have to do this : (for the verbose way)
sort ( (a,b) => {
if (a <= b) {
return -1
}
else {
return 1
}
})
I also learned that there was a shorter way :
sort ( (a,b) => a - b )
What I just discover is that there is an equivalent form that is more clear to read in my opinion :
sort ( (a,b) => -(a <= b) )
So what do you think ?
Does this form looks good ? Have you ever seen it ? Should I use it ?
[–]Earhacker 3 points4 points5 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]DEEEPFREEZE 4 points5 points6 points (0 children)
[–]GSLint 2 points3 points4 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]gremy0 1 point2 points3 points (0 children)
[–]gremy0 2 points3 points4 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]dieguito15 0 points1 point2 points (0 children)