Created
October 25, 2018 17:22
-
-
Save mingbackmountain/f037ef78b715aa521072c3ee6ebfef50 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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