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, }, ]; // =============================================== 2 ================================================ // let uniqSuit = new Set(); function getSuits(cardData) { cardData.forEach((element) => { uniqSuit.add(element.suit); }); return Array.from(uniqSuit); // write your code here } console.log(getSuits(cardData)); /** 2. write a function which returns the list of available suits in the above data * ans => ["heart", "club", "diamond"] */
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter