Skip to content

Instantly share code, notes, and snippets.

@michiel
Last active Oct 2, 2015
Embed
What would you like to do?
some sorting in coffeescript
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