Last active
May 19, 2017 19:54
-
-
Save simongle/1ac9afb62fee337e5b2b1355b64104f3 to your computer and use it in GitHub Desktop.
Learnyounode exercises
This file contains hidden or 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
console.log("HELLO WORLD"); |
This file contains hidden or 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 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); |
This file contains hidden or 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 newLines = fs.readFileSync(process.argv[2], 'utf8').split('\n'); | |
console.log(newLines.length -1); |
This file contains hidden or 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 numLines = fs.readFile(process.argv[2], 'utf8', function(err, data) { | |
if (err) throw err; | |
console.log(data.split('\n').length -1); | |
}) |
This file contains hidden or 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'); | |
// 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) : ''; | |
}) | |
}); |
This file contains hidden or 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, fileExt){ | |
fs.readdir(dir, function(err, list){ | |
if (err) throw err; | |
list.forEach(function(file){ | |
(path.extname(file) == '.' + fileExt) ? console.log(file) : ''; | |
}) | |
}) | |
}; |
This file contains hidden or 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 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