I am working on a WebApp to play music that I parse from twitter while I am work. currently I am storing the songs by song Id that I get from SoundCloud. But I am not able to organize it to play the last song played. I looked at changing how I have the key in my database to the date but then I would have to check if the song already exists and I think that would be harder to do. But I would like to figure out how to compare the date and then display the most recent song.
My data looks like this:
"6655480" : {
"Date" : "12/16/2014 2:58:39 am",
"SongName" : "The Island (Steve Angello, An21 & Max Vangeli remix)",
"Tweet" : "Pendulum/Steve Angello/An21/Vangeli - The Island playing on #BPM - @sxmElectro",
"uri" : "https://api.soundcloud.com/tracks/6655480"
}
I tried this:
$scope.Song.sort(function(a,b){
var c = new Date(a.Date);
var d = new Date(b.Date);
return c-d;
});
But it is not working. Any help is appreciated.
I get $scope.Song like this:
var ref = new Firebase("https://app.firebaseio.com/SC");
var sync = $firebase(ref);
$scope.Song = sync.$asArray();
UPDATE:
So I have tried to solve this by doing:
$scope.log = [];
angular.forEach(values, function(value, key) {
value.sort(function(a,b){
var c = new Date(a.Date);
var d = new Date(b.Date);
return c-d;
}
}, log);
But now nothing works. What is the issue with my syntax? is this the proper way to do this?