Learn Advanced Array Methods by Building a Statistics Calculator - Step 6

Can someone explain the solution to me ?

I found the solutions of the challenge, so i won’t past it here, but i don’t understand why it’s working that way and not this way :

const variable = array.map(el =>Number(el));
const secondVariable = variable.filter(NaN);

Why the step of filtered and assigned the filtered value have to be separated ? I can’t figure out why we have to wait the result to assign them to a new variable.

Sorry if it’s an obvious question, I’d rather ask than stay stupid

in what sense separated? I am not sure I understand your question, can you give more details?

It’s really hard to explain it without giving the answer to that challenge. Turn out, after going further in it, that it’s made to understand “better” the way the method works

is this a question about chaining methods vs not chaining methods?

Yes ! Sometimes in some challenge, I can’t figure if I can or cannot use a chaining method ! Are they any special rules about chaining methods ?

if you want to look at the output of a method before feeding it to an other method, you can’t chain — for example debugging well usually requires not chaining methods.
Chaining vs. not chaining can also be a stylistic or readability choice.

The only rule is that you can chain a method only if the previous method outputs the right datatype

1 Like

Oh ok, I’m getting there, slowly tho, but I’m seeing how that works more clearly, thank you for the explanation @ILM !

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.