Uh oh!
There was an error while loading. Please reload this page.
Fix sort function of files multiple selection actions - #28164
Conversation
julien-nc
commented
Jul 26, 2021
/backport to stable22 |
Yes and no. varnumbers=[4,2,5,1,3];numbers.sort(function(a,b){returna-b;});console.log(numbers);// [1, 2, 3, 4, 5]
|
julien-nc
commented
Jul 26, 2021
I think it is because, currently, sort function return values are wrong as a boolean is returned. So the array is actually not sorted, its order stays the same. And sorry for the poor description of what's expected of the sort function 😁 |
skjnldsv
commented
Jul 26, 2021
then shouldn't it be |
Well what if the order is undefined? (which is the case for the recent tag multiselect action 😁) We would need something like return(a.order||1000)-(b.order||1000)to make sure the ones without order are placed at the end. |
skjnldsv
commented
Jul 26, 2021
If the order is undefined it's most likely going to break somewhere else, no? xD |
artonge
commented
Jul 26, 2021
What's the state here ? Just tested and: [1,5,-1,undefined,-100].sort((a,b)=>a-b)Array(5)[-100,-1,1,5,undefined][1,5,-1,undefined,-100].sort((a,b)=>b-a)Array(5)[5,1,-1,-100,undefined]So this should be fine I guess as undefines are at the end returnb.order-a.order |
Signed-off-by: Julien Veyssier <eneiluj@posteo.net>
91cc102 to
d6b4944Comparejulien-nc
commented
Jul 26, 2021
@artonge Very true, thanks. Let's roll.
State is now yours to decide 😁. |
Javascript array sort function must return -1, 0 or 1 😁.
This can be backported to stable22 only.