CardProblem-3
Mon Oct 03 2022 11:26:46 GMT+0000 (Coordinated Universal Time)
Saved by
@j_jivan
#javascript
const cardData = [
{
suit: "heart",
value: 7,
},
{
suit: "club",
value: 8,
},
{
suit: "club",
value: 2,
},
{
suit: "diamond",
value: 2,
},
{
suit: "diamond",
value: 5,
},
{
suit: "club",
value: 10,
},
];
// ================================================ 3 =============================================== //
const Obj = {};
function getSuitCount(cardData) {
for (const card of cardData) {
Obj[card.suit] = Obj[card.suit] ? Obj[card.suit] + 1 : 1;
}
return Obj;
// write your code here
}
getSuitCount(cardData);
/**
* 3. write a function which returns an object with the suits as its key and its total count as its value
* ans => { heart:1, club:3, diamond:2,}
*/
content_copyCOPY
Comments