Last active
October 2, 2015 17:48
-
-
Save michiel/2287746 to your computer and use it in GitHub Desktop.
some sorting in coffeescript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sort = (objs, attrs) -> | |
dojo.map( | |
(dojo.map objs, (obj) -> | |
arr = [obj] | |
dojo.forEach attrs, (attr) -> | |
arr.push obj.get(attr) | |
arr | |
).sort( | |
(attrsA, attrsB) -> | |
i = 1 | |
while i < attrs.length | |
[a, b] = [attrsA[i], attrsB[i]] | |
# | |
# This is where CS has nothing on JS | |
# OMFG isn't this ugly and wasteful | |
# | |
if a is not b | |
if attrs[i][1] == "asc" | |
if a > b | |
return 1 | |
else | |
return -1 | |
else | |
if a < b | |
return -1 | |
else | |
return 1 | |
i++ | |
return 0 | |
), (arr) -> | |
arr[0] | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment