Created
May 1, 2017 17:13
-
-
Save pllearns/6fa1090a7564852fb5c47ea67460bd3c to your computer and use it in GitHub Desktop.
Solutions to Learnyounode ---> Make it Modular
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
var readFile = require('./readFile.js') | |
var file = process.argv[2] | |
var filtered = process.argv[3] | |
readFile(file, filtered, function(err, list) { | |
if (err) { | |
return console.log(err) | |
} | |
list.forEach(function (list) { | |
console.log(list) | |
}) | |
}) | |
var readFile = require('./readFile.js') | |
var file = process.argv[2] | |
var filtered = process.argv[3] | |
readFile(file, filtered, function(err, list) { | |
if (err) { | |
console.log(err) | |
} | |
list.forEach(function(file) { | |
console.log(file) | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs') | |
var path = require('path') | |
module.exports = function (dir, stringFind, callback) { | |
fs.readdir(dir, function (err, list) { | |
if (err) { | |
return callback(err) | |
} | |
list = list.filter(function (file) { | |
return path.extname(file) === '.' + stringFind | |
}) | |
callback(null, list) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment