key - Combining two arrays into value pairs to make a full deck of cards -


i trying combine 2 two arrays make full deck of cards looks so:

[{card: "a", suit: "d"}, {card: "a", suit: "c"}, {card: "a", suit: "s"},    {card: "a", suit: "h"}, {card: "2", suit: "d"}.....] 

.... have far:

function newdeck(ranks, suits){ var ranks = [ "a", "2", "3", "4", "5", "6", "7", "8", "9", "10", "j", "q", "k"]  var suits = ["d", "c", "s", "h"]  var deck= []    (i = 0; < suits.length; i++) {    (j = 0; j < ranks.length; j++) {        this.deck[ranks.length*i+j] = new card(ranks[j], suits[i]);   } } console.log(newdeck) } 

using array.foreach can following:

var ranks = [ "a", "2", "3", "4", "5", "6", "7", "8", "9", "10", "j", "q", "k"]; var suits = ["d", "c", "s", "h"]; var deck= []; suits.foreach(function(suit){   ranks.foreach(function(rank){     deck.push(new card(rank, suit));   }) }); 

edit: , in case haven't written card method yet:

function card(rank, suit){   this.card = rank;   this.suit = suit; } 

Comments