Learn Basic String and Array Methods by Building a Music Player - Step 73

Tell us what’s happening:

Your code so far

Use the filter() method on userData?.songs. Pass in song as the parameter of the arrow function callback and use implicit return to check if song.id is strictly not equal to id. Assign all of that to the userData.songs.

Note: You should not use optional chaining when you assign the result of userData?.songs.filter to userData.songs because the allSongs array will not be undefined or null at that point.

i have tried to place the song . id strictly to not equal id and assign it as per challenge however i am getting told:

Your filter method should implicitly return `song.id !== id`
const deleteSong = (id) => {
 userData?.songs.filter=(song)=> {userData.songs = song.id !== id}


The challenge seed code and/or your solution exceeded the maximum length we can port over from the challenge.

You will need to take an additional step here so the code you wrote presents in an easy to read format.

Please copy/paste all the editor code showing in the challenge from where you just linked.

Replace these two sentences with your copied code.
Please leave the ``` line above and the ``` line below,
because they allow your code to properly format in the post.

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge Information:

Learn Basic String and Array Methods by Building a Music Player - Step 73

Hi Syed! The filter method should look something like this:

variableName.filter((parameter)=>{do something here but **return a boolean**});

Now, the instructions say to implicitly return the boolean check (all filters should ultimately end in returning a boolean (true or false)). This just means you have only one line after your arrow and you do not use the brackets. That one line of code is returned to the function (hence, implicit because you do not use the return keyword).

userData?.songs.filter=((song)=> {userData.songs = song.id !== false})

still not passing can u be slightly more specific

You’re getting there, but you’re making things more difficult than you need. The instructions for this step give you a fantastic example to start with:

const numsGreaterThanThree = numArr.filter((num) => num > 3);

What comes directly after the word filter?
Does the example use curly brackets?

userData?.songs.filter=((song)=> song.id !== id)

i still dont get it

syntax error.

const a = b.filter(...)  // correct
const a = b.filter=(...)  // wrong

More filter examples here Array.prototype.filter() - JavaScript | MDN

i do not understand this

To use filter() function of an Array, I will use

Array.filter(() => {})

But i should not assign something to filter :

Array.filter = () // why would you assign something to filter ?

ok i am being told different things to use curly brackets to not use curly brackets everyone is telling me different things which i have all tried none of it is passing

Hi Syed, the first thing everyone is telling you is:
Do not use an equal sign directly after the word “filter” .
The second thing is that for this task, the curly brackets are not needed.

Break it down to first principles: What is the purpose of filtering something?
Let’s say you have this array: [1,4,8]
But you are interested only in numbers bigger than 3. What would you do? Forgetting the “code”, you want to filter this array. How would you do that? You would compare each number to 3:
Is “1” bigger than 3? No. (False)
Is “4” bigger than 3? Yes. (True)
Is “8” bigger than 3? Yes. (True)
Then you gather your numbers that are bigger than 3 into a new array: [4, 8].

This is exactly what the filter function does. The filter function starts with one array, does some comparisons on each element, and then gives you a new array with only those elements.

So in my example, we would say:
const arrayBiggerThanThree = originalArray.filter((element)=>element>3);

userData?.songs.filter((song) => song.id !== id)

from what i am undestanding is i have to not use curly and in filter i use song element and then pass arrow syntax with this arguement?

Your filter method should implicitly return song.id !== id

ok so next i am supposed to reolve this issue now correct? step by step

Yes! Now you just need to set all of this equal to what the instructions said.

Taking it back to my lengthy example, in this step we do not want to create a new array: we are replacing the original array with the newly filtered one. In my example, it would look like:

originalArray = originalArray.filter((element)=>element>3);

 userData.songs=userData?.songs.filter((song) => song.id !== id)

so in the end i needed to move this before the whole thing for it to work

1 Like

Now you have got it!

1 Like