Learnyounode: MAKE IT MODULAR

Hi to everyone!

So, here is my code:

When I try to verify: “ACTUAL = EXPECTED”, but I didn’t pass exercise and see some error.

Pls, help me. Where I’m wrong?

Here’s my guess:

The callback function must be called using the idiomatic node(err, data)
convention. This convention stipulates that unless there’s an error, the
first argument passed to the callback will be null, and the second will be
your data. In this exercise, the data will be your filtered list of files,
as an Array.

It looks like you’re passing strings to your callback, rather than an array.

Thank you.
This is official solution:

And yes, even now I’m really don’t understand, why my code was failed.


The forEach function is weird. It doesn’t do what you expect if a condition returns false. It’s meant to do some sort of action on each element in an array.

I found this stack overflow answer helpful when I ran into this like last week:

I had the same error and I solved it by filtering the elements first and then passing the filtered array to the callback function, like this:

files = files.forEach(function(file) {
if (path.extname(file) === “.” + flts) {
return file;

//after filtering the array call the callback function passing the filtered array
callback(null, files);

and in your main program just print each element of the array passed.

hope it helps!.