Shuffling and sorting arrays


#1

Hi, I’m building a music player with Ember.js and now I’m ready to build a shuffle function.

Without shuffle, I’m able to go to previous and next using something like this:

this.get('tracks').objectAt( (this.get('currentTrackIndex') + 1) );

With shuffle, next is a random item in the array but prev should follow your listening history. Like iTunes and many others.

How would you do this? Maintain a “playbackHistory” array or?


#2

You can do something like this: http://jsbin.com/navuxumovo/1/edit?html,js,output

However, this isn’t an ember design discussion and likely belongs on StackOverflow.


#3

Thanks so much, it’s perfect! Helped us integrate shuffle in our upcoming Ember.js music player.