Deborah
Deborah

Reputation: 3

how to sort an array in coffeescript

I have an array like this:

[Object { id=1027355606, name="Canada Post", 
job_assignments=[Object { id=1027355607,    user_id=976369075, sequence=-1}]}, 
Object { id=1027355607, name="Ottawa Marriott Hotel", 
job_assignments=[Object { id=1027355606, user_id=976369075, sequence=1}]}]

and I want to sort the array by the sequence number (from smallest to biggest).

Upvotes: 0

Views: 1057

Answers (1)

user229044
user229044

Reputation: 239491

This isn't a CoffeeScript question, it's a JavaScript question. CoffeeScript doesn't add any new sorting functionality. You want Array.prototype.sort.

The CoffeeScript syntax would be

myArray.sort (a, b) ->
  a.job_assignments.sequence - b.job_assignments.sequence

Upvotes: 1

Related Questions