var array = [{"id":"0", "stopDate":null},
{"id":"1", "stopDate":"10/06/2014"},
{"id":"2", "stopDate":null},
{"id":"3", "stopDate":"09/06/2014"}];
I have array of objects as above and want to sort by stop date using underscore. I am using following function to do so.
_.sortBy(array, "stopDate"); // asc
_.sortBy(array, "stopDate").reverse(); //desc
Above method sorts the date value properly but ignores null. So the output for asc is coming out to be
var actual= [{"id":"0", "stopDate":null},
{"id":"3", "stopDate":"09/06/2014"},
{"id":"2", "stopDate":null},
{"id":"1", "stopDate":"10/06/2014"}];
But I am expecting null to be grouped together and should appear one after other.
var expected= [{"id":"0", "stopDate":null},
{"id":"2", "stopDate":null},
{"id":"3","stopDate":"09/06/2014" },
{"id":"1", "stopDate":"10/06/2014"}];