diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/js/services.js | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/app/js/services.js b/app/js/services.js index 8a2ced3..622717a 100644 --- a/app/js/services.js +++ b/app/js/services.js @@ -31,12 +31,14 @@ app.service('pathService', function() { //select the songs var selection = []; var tuning = .5; - songListCopy.sort(function(song){ - console.log(song.minDist, (tuning + tuning*Math.random())*song.minDist) - return (tuning + tuning*Math.random())*song.minDist;} - ); + angular.forEach(songListCopy, function(song){ + song.rand = (tuning + tuning*Math.random())*song.minDist; + }); + songListCopy.sort(function(a,b){return a.rand-b.rand;}); + //take from the sorted list util we reach the desired duration while(duration > 0 && songListCopy.length > 0){ var removed = songListCopy.splice(0, 1); + console.log(removed[0].minDist); selection.push(removed[0]); duration -= 10; } |