Skip to content

Instantly share code, notes, and snippets.

@wfendler
Created July 11, 2013 19:18
Show Gist options
  • Save wfendler/5978388 to your computer and use it in GitHub Desktop.
Save wfendler/5978388 to your computer and use it in GitHub Desktop.
Building a memory/matching game. I want to start with 6 divs, clone them, and randomize the order. At this point I have an array with 12 items. Is this correct so far? I've found some functions to randomize the order of an array. That shouldn't be a problem. Once I have that, is it fastest to do a for loop and .append() to the page? Or should I …
this.$initialCardCollection.length = $('.js-memory-card');
this.fullCardCollection = [];
// this.$initialCardCollection.length has the original divs on the page that i'll clone.
for ( var i = 0; i < this.$initialCardCollection.length; i++ ) {
var $thisCard = $(this.$initialCardCollection[i]);
this.fullCardCollection.push( $thisCard );
this.fullCardCollection.push( $thisCard.clone() );
}
@wfendler
Copy link
Author

    // Build array with duplicates
    for ( var i = 0; i < this.$initialCardCollection.length; i++ ) {
      for ( var index = 0; index < 2; index++ ) {
        this.fullCardCollection.push( $(this.$initialCardCollection[i]).html() );
      }
    }

@wfendler
Copy link
Author

I put a for loop in your for loop so you can loop while you loop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment