scrimba
JS Challenges
Solution Pt 2: Collect Unique Genre Tags
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Solution Pt 2: Collect Unique Genre Tags
AboutCommentsNotes
Solution Pt 2: Collect Unique Genre Tags
Expand for more info
index.js
run
preview
console
import mediaData from "./data.js";

/* Find All Unique Tags

As a software dev at ScrimFlix, you're working on a feature
to let users browse TV shows by tag. The first step is to collect all
the tags from our data into a new array. Then we'll need
to filter out the duplicate tags.

Write a function that takes in the media data and returns
a flat array of unique tags.

Expected output:
["supernatural", "horror", "drama",
"fantasy", "reality", "home improvement", "comedy", "sci-fi", "adventure"]

*/

function getUniqueTags(data){
const tags = data.map(podcast => podcast.tags).flat();
const uniqueTags = [];

tags.forEach(tag => {
if(!uniqueTags.includes(tag)){
uniqueTags.push(tag)
}
})

return uniqueTags;
}

console.log(getUniqueTags(mediaData));

Console
[
"supernatural"
,
"horror"
,
"drama"
,
"fantasy"
,
"reality"
,
"home improvement"
,
"comedy"
,
"sci-fi"
,
"adventure"
]
,
/index.html
-3:23