Closed SigmaEva closed 8 years ago
You are currently getting the correct results when you run the program, but there is one step missing to make the solution pass. In your module, the second argument of the callback is meant to be an array. At the moment you apply it to just an item of an array, as you have the callback inside the function of the forEach method.
What you need to do is to filter your list and run the callback with the filtered list as the second argument.
You will also have to change the callback in the original file that requires the module, as it will now take in an array.
Hope that helps
code file:
var mymodule = require('./mymodule.js');
var path = require('path');
mymodule(process.argv[2],process.argv[3],function(err,list){
if(err)throw err;
console.log(list.join("\n"));
});
module file:
var path = require('path');
var fs = require('fs');
module.exports = function(directory,extention,callback){
fs.readdir(directory, function (err, list) {
if(err){
return callback(err);
}
var filter_list=[];
list.forEach(function (data) {
if (path.extname(data) === '.' + extention){
filter_list.push(data);
}
})
return callback(null,filter_list);
})
}
sorry for the late reply :( thanx a lot to both of you!
:tada:
Hey all, i am getting a fail in learnyounode - make it modular. These are my results :
✓ Submission results match expected ✓ Additional module file exports a single function ✓ Additional module file exports a function that takes 3 arguments ✓ Additional module file handles errors properly ✓ Additional module file handles callback argument ✓ Additional module file returned two arguments on the callback function ✗ Your additional module file [mymodule.js] did not return an Array object as the second argument of the callback ✓ Additional module file returned two arguments on the callback function ✗ Your additional module file [mymodule.js] did not return an Array object as the second argument of the callback /usr/local/lib/node_modules/learnyounode/node_modules/workshopper-exercise/exercise.js:177 processors[i].call(self, mode, function (err, pass) { ^ TypeError: Cannot call method 'call' of undefined
And this is my code :
and the mymodule file
thanx in advnce :)