Shuffling and sorting arrays

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?

You can do something like this: JS Bin - Collaborative JavaScript Debugging

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

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