These are chat archives for canjs/canjs

24th
Jul 2015
Justin Meyer
@justinbmeyer
Jul 24 2015 15:37
@akagomez 's thoughts on comparators: https://gist.github.com/akagomez/c7d7111e4490e9dd49eb
I think we should support a function and a string name only
Chris Gomez
@akagomez
Jul 24 2015 15:39
@justinbmeyer So you’re for “attr” === ascending and “-attr” === descending?
Justin Meyer
@justinbmeyer
Jul 24 2015 15:39
not for that ... but not against it
I just don't think we should support object comparators
regarding reversing the sort order ... does lodash do this?
b/c if not ... I'm not sure it's worth it
b/c if we have the derive plugin ... we could make a fast .reverse()
so you could do
.sort("foo").reverse()
Chris Gomez
@akagomez
Jul 24 2015 15:42
I had considered that while I was writing the original sort plugin. It’d be twice the work.
Well, not twice. The first would be O(n^2), the second would be O(log^2(n)).
Once can-derive is “sorted” I’d like to use can-redblacktree to get the sort plugin’s complexity down to O(log(n)). That’d be sweet.
Chris Gomez
@akagomez
Jul 24 2015 15:49
I think there’s an argument to be made for abstracting away multiple comparators. Sorting is fairly conventional and a typical requirment of any app. If we could make a turn-key solution, it’d be a big win for devs.
Chris Gomez
@akagomez
Jul 24 2015 18:35
Actually, the sort plugin can’t benefit from can-redblacktree because the number of swaps would go up.
In fact, I should probably rewrite the sort plugin to use cycle sort: https://en.wikipedia.org/wiki/Cycle_sort
Even fewer swaps than selection sort.
Justin Meyer
@justinbmeyer
Jul 24 2015 19:29
@akagomez what do you mean it would be twice the work?
it only takes O(n) to reverse a list
I disagree that it's a typical requirement because I've never worked on an app that has needed it
most apps rely on server-side sorting
Chris Gomez
@akagomez
Jul 24 2015 19:50
@justinbmeyer You’re right, I misspoke about it being twice the work.
@justinbmeyer You’ve never worked on an app that needed it? How can that be? How would you handle sorting the rows of a table by column?