Skip to content

Instantly share code, notes, and snippets.

@michiel
Last active October 2, 2015 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michiel/2287746 to your computer and use it in GitHub Desktop.
Save michiel/2287746 to your computer and use it in GitHub Desktop.
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