I have an array of objects as follows:
c = [{a: null}, {a: 12}, {a: 1}, {a: 50}, {a: 2}, {a: null}]
I want to kind-of sort them by the objects having values first then objects with null.
What I tried is:
c.sort(function(b) { return b.a ? -1 : 1 })
OUTPUT
[{a: 2}, {a: 50}, {a: 1}, {a: 12}, {a: null}, {a: null}]
EXPECTED OUTPUT
[{a: 12}, {a: 1}, {a: 50}, {a: 2}, {a: null}, {a: null}]
How can I achieve this?