First of all, excuse my English. I will try to explain the best that I can.
I want to develop a dominoes console game.
I stored all the dominoes into an array named dominoes
.
function createNewDominoes(dominoes) {
newDomino = {
a: Math.floor((Math.random() * 7) - 0),
b: Math.floor((Math.random() * 7) - 0),
tipo: null
}
newDominoFlipped = {
a: nuevaFicha.b,
b: nuevaFicha.a,
tipo: null
}
console.log(nuevaFicha, nuevaFichaVolteada)
if ((includes(dominoes, newDomino)) || (includes(dominoes, newDominoFlipped))) {
console.log("Element already exist")
} else {
array.push(nuevaFicha)
}
}
I am used Node.js, and I included array-includes modules into the app.js file, that allows me to check the element of my array.
The thing is that when I get the array, the function return 28 elements, that's okay, but some are repeated. Example:
[ { a: 3, b: 0, tipo: null },
{ a: 5, b: 2, tipo: null },
{ a: 1, b: 4, tipo: null },
{ a: 1, b: 6, tipo: null },
{ a: 2, b: 4, tipo: null },
{ a: 4, b: 2, tipo: null },
{ a: 4, b: 2, tipo: null },
{ a: 3, b: 3, tipo: null },
{ a: 5, b: 5, tipo: null },
{ a: 3, b: 4, tipo: null },
{ a: 0, b: 6, tipo: null },
{ a: 6, b: 0, tipo: null },
{ a: 4, b: 4, tipo: null },
{ a: 6, b: 3, tipo: null },
{ a: 5, b: 2, tipo: null },
{ a: 3, b: 4, tipo: null },
{ a: 3, b: 5, tipo: null },
{ a: 2, b: 3, tipo: null },
{ a: 3, b: 4, tipo: null },
{ a: 3, b: 3, tipo: null },
{ a: 5, b: 3, tipo: null },
{ a: 0, b: 1, tipo: null },
{ a: 2, b: 2, tipo: null },
{ a: 0, b: 3, tipo: null },
{ a: 2, b: 3, tipo: null },
{ a: 4, b: 4, tipo: null },
{ a: 0, b: 4, tipo: null },
{ a: 5, b: 1, tipo: null } ]
I need to get all the 28 dominoes, but they can't be repeated or flipped-repeated.
Hope you can help me