-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Fix sort function of files multiple selection actions #28164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
/backport to stable22 |
|
Yes and no. var numbers = [4, 2, 5, 1, 3];
numbers.sort(function(a, b) {
return a - b;
});
console.log(numbers);
// [1, 2, 3, 4, 5]
|
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 😁 |
|
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. |
|
If the order is undefined it's most likely going to break somewhere else, no? xD |
|
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 return b.order - a.order |
Signed-off-by: Julien Veyssier <[email protected]>
91cc102 to
d6b4944
Compare
|
@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.