Skip to content

Instantly share code, notes, and snippets.

@rwjblue
Forked from rondale-sc/blerg.js
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rwjblue/a1f36f05722e8917b076 to your computer and use it in GitHub Desktop.
Save rwjblue/a1f36f05722e8917b076 to your computer and use it in GitHub Desktop.
function randomDeck(player, n) {
var store = player.store;
var deck = player.get('deck');
var r, promises = [];
return store.findAll('card')
.then(function(cards){
var lastIndex = cards.get('length') - 1;
for(var i = 0; i < n; i++) {
r = randomInt(lastIndex);
var card = cards.objectAt(r);
var promise = store.createRecord('deck-card', {
card: card,
player: player
}).save();
promises.push(promise);
}
return player.save();
})
.then(function(){
return Ember.RSVP.all(promises);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment