curriculum/challenges/english/blocks/daily-coding-challenges-javascript/698a1a73ade5ac0e19180fa9.md
Given an array of playing cards, return a new array with the numeric value of each card.
Card Values:
"A") has a value of 1."2" - "10") have their face value: 2 - 10, respectively."J"), Queen ("Q"), and King ("K") are each worth 10.Suits:
"S"), Clubs ("C"), Diamonds ("D"), or Hearts ("H").Card Format:
"valueSuit". For Example: "AS" is the Ace of Spades, "10H" is the Ten of Hearts, and "QC" is the Queen of Clubs.cardValues(["3H", "4D", "5S"]) should return [3, 4, 5].
assert.deepEqual(cardValues(["3H", "4D", "5S"]), [3, 4, 5]);
cardValues(["AS", "10S", "10H", "6D", "7D"]) should return [1, 10, 10, 6, 7].
assert.deepEqual(cardValues(["AS", "10S", "10H", "6D", "7D"]), [1, 10, 10, 6, 7]);
cardValues(["8D", "QS", "2H", "JC", "9C"]) should return [8, 10, 2, 10, 9].
assert.deepEqual(cardValues(["8D", "QS", "2H", "JC", "9C"]), [8, 10, 2, 10, 9]);
cardValues(["AS", "KS"]) should return [1, 10].
assert.deepEqual(cardValues(["AS", "KS"]), [1, 10]);
cardValues(["10H", "JH", "QH", "KH", "AH"]) should return [10, 10, 10, 10, 1].
assert.deepEqual(cardValues(["10H", "JH", "QH", "KH", "AH"]), [10, 10, 10, 10, 1]);
function cardValues(cards) {
return cards;
}
function cardValues(cards) {
const values = [];
for (let card of cards) {
let valueStr = card.slice(0, card.length - 1);
let value;
if (valueStr === "A") {
value = 1;
} else if (["J", "Q", "K"].includes(valueStr)) {
value = 10;
} else {
value = parseInt(valueStr, 10);
}
values.push(value);
}
return values;
}