Skip to content

Instantly share code, notes, and snippets.

@mingbackmountain
Created October 25, 2018 17:22
Show Gist options
  • Save mingbackmountain/f037ef78b715aa521072c3ee6ebfef50 to your computer and use it in GitHub Desktop.
Save mingbackmountain/f037ef78b715aa521072c3ee6ebfef50 to your computer and use it in GitHub Desktop.
function generateData() {
const symbolCard = ["C", "D", "H", "S"];
const numberCard = [
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"0",
"J",
"Q",
"K",
"A"
];
let cardList = [];
for (let indexSymbol = 0; indexSymbol < symbolCard.length; indexSymbol++) {
for (let indexNumber = 0; indexNumber < numberCard.length; indexNumber++) {
cardList.push(numberCard[indexNumber] + symbolCard[indexSymbol]);
}
}
return cardList;
}
function cardAt(number) {
const cardList = generateData();
if (typeof number === "number") {
let index = Math.abs(number % 52);
return cardList[index];
} else {
throw new Error("Please input number");
}
}
console.log(cardAt(0));
console.log(cardAt(1));
console.log(cardAt(34));
console.log(cardAt(35));
console.log(cardAt(103));
console.log(cardAt(51));
console.log(cardAt("ss"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment