Skip to content

Instantly share code, notes, and snippets.

@simongle
Last active May 19, 2017 19:54
Show Gist options
  • Save simongle/1ac9afb62fee337e5b2b1355b64104f3 to your computer and use it in GitHub Desktop.
Save simongle/1ac9afb62fee337e5b2b1355b64104f3 to your computer and use it in GitHub Desktop.
Learnyounode exercises
console.log("HELLO WORLD");
var inputs = process.argv;
inputs.splice(0,2);
var nums = inputs.map(function(x){
return +x;
}).reduce(function(acc, val){
return acc + val;
}, 0);
console.log(nums);
var fs = require('fs');
var newLines = fs.readFileSync(process.argv[2], 'utf8').split('\n');
console.log(newLines.length -1);
var fs = require('fs');
var numLines = fs.readFile(process.argv[2], 'utf8', function(err, data) {
if (err) throw err;
console.log(data.split('\n').length -1);
})
var fs = require('fs');
var path = require('path');
// console.log(process.argv[2]);
var fileExt = process.argv[3];
var fileList = fs.readdir(process.argv[2], function(err, list){
if (err) throw err;
list.forEach(function(file){
(path.extname(file) == '.' + fileExt) ? console.log(file) : '';
})
});
var fs = require('fs');
var path = require('path');
module.exports = function(dir, fileExt){
fs.readdir(dir, function(err, list){
if (err) throw err;
list.forEach(function(file){
(path.extname(file) == '.' + fileExt) ? console.log(file) : '';
})
})
};
var fileFilter = require('./program6_1');
fileFilter(process.argv[2], process.argv[3]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment