I want to create an array that has the values from 1 to 13, four times. This final array should have 52 positions and be something like this:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
I already created the array filled with numbers from 1 to 13
let suit = Array.from(new Array(13), (x, index) => index + 1)
And want to push four times the values on this "suit" array to a final array called "deck".
To do this I've tried the following code:
let suit = Array.from(new Array(13), (x, index) => index + 1)
let suitsNumber = 4
let deck = []
for(let i = 0; i < suitsNumber; i++ ) {
deck.push(suit)
}
The problem is that the resulting array "deck" is a bidimensional array with length four and in each position is the array suit:
[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]]
Can someone tell why is not working as I expected?