It was hard to give it a good title to describe what this is but that's the best I came up with. Anyway, this simply creates a deck of cards and then removes the hole cards. Performance is crucial since it needs to make thousands of iterations of this new deck creation, shuffle and hole card removal.
It's very fast to create the deck but the hole card removal function has a huge performance hit since I can't find any easy way to remove an element in JS.
const suits = ['s', 'h', 'd', 'c'];
const remove = ['10s', '11s', '13h', '9c'];
var deck = mkDeck();
shuffle(deck)
rmvHole();
// Functions
function rmvHole() {
for (let i = 0; i < remove.length; i++) {
const key = Object.keys(deck).find(key => deck[key] === remove[i]);
deck[key] = null;
}
}
function mkDeck() {
let arr = [];
for (let s = 0; s < 4; s++) {
for (let i = 2; i < 15; i++) {
arr.push(i + suits[s]);
}
}
return arr;
}
function shuffle(a) {
for (let i = a.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[a[i], a[j]] = [a[j], a[i]];
}
return a;
}
console.log(deck);
.as-console-wrapper { max-height: 100% !important; top: auto; }