-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Problem using Array sort in phantomJS #11090
Comments
Thanpolas@gmail.com commented:
|
ariya.hi...@gmail.com commented:
|
I have a problem seemingly related to the issue described above. Whenever I sort an Array in phantomJS using a sort callback of the form Hopefully someone can point me in the right direction. |
After some testing I found out that although the meaning of the values 1 and -1 in a sorting callback in phantomJS is opposite to their meaning in Chrome in that context, the arguments are also passed in in reverse order, so that the final result is the same. My problem was caused by the fact that Chrome happily executes |
#bump it indeed happens when any true becomes false, including the first example mentioned on var a = [
{ name: 'foo', index: 4 },
{ name: 'bar', index: 2 },
{ name: 'fooz', index: 3 },
{ name: 'baz', index: 0 }
].sort(function (a, b) {
var r = a.index > b.index;;
console.log(r);
return r;
});
console.log(a.map(function (tag) { return tag.index})); Where I guess phantomjs output
v8 output
|
Thank you for the clues, @esposito and @zanona. We had a sort like this:
PhantomJS was sorting it incorrectly because it inverts the a and b. Revising it to the following worked:
I would be inclined to still consider this an open bug in PhantomJS. Why sort in reverse order? |
How is this closed? |
This was closed over a year ago because the original submitter said it was his mistake. If there is an additional problem, please open a new issue as closed ones aren't tracked. Finally, this is likely already fixed in PhantomJS 2.0 (unstable |
Thanpolas@gmail.com commented:
Disclaimer:
This issue was migrated on 2013-03-15 from the project's former issue tracker on Google Code, Issue #1090.
🌟 3 people had starred this issue at the time of migration.
The text was updated successfully, but these errors were encountered: