From 9aea9b0ddc139f4a66870137bd1f4e65928f133b Mon Sep 17 00:00:00 2001 From: manonthemat Date: Sun, 11 Jan 2015 14:38:14 -0800 Subject: [PATCH 1/2] use of console.error in "each" problem when printing an error to the console, it's a good idea to use console.error as an alternative to console.log. --- problems/each/problem.txt | 8 ++++---- problems/each/solution.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/problems/each/problem.txt b/problems/each/problem.txt index 2b2c359..693b831 100644 --- a/problems/each/problem.txt +++ b/problems/each/problem.txt @@ -1,6 +1,6 @@ Occasionally you will want to call the same function multiple times, but with different inputs, without caring about the return data but to check if any call -throws an error (sometimes not even that). This is where async.each is useful. +throws an error (sometimes not even that). This is where async.each is useful. For example, the following will make three calls using the values in the array: var http = require('http') @@ -25,9 +25,9 @@ For example, the following will make three calls using the values in the array: req.end(); }, function(err){ - if (err) console.log(err); + if (err) console.error(err); }); Create a program that will receive two URLs as the first and second command-line -arguments. Then using `http.get`, create two GET requests to these URLs and -console.log any errors. +arguments. Then using `http.get`, create two GET requests to these URLs and +console.error any errors. diff --git a/problems/each/solution.js b/problems/each/solution.js index 0594e32..51047bc 100644 --- a/problems/each/solution.js +++ b/problems/each/solution.js @@ -14,5 +14,5 @@ async.each(process.argv.slice(2), function(item, done){ }); }, function(err){ - if(err) console.log(err); + if(err) console.error(err); }); From 92a0fcfbf947b36ca79aa989e8643965fb234b10 Mon Sep 17 00:00:00 2001 From: manonthemat Date: Wed, 7 Oct 2015 22:32:44 -0700 Subject: [PATCH 2/2] removed old each problem.txt --- problems/each/problem.txt | 33 --------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 problems/each/problem.txt diff --git a/problems/each/problem.txt b/problems/each/problem.txt deleted file mode 100644 index 693b831..0000000 --- a/problems/each/problem.txt +++ /dev/null @@ -1,33 +0,0 @@ -Occasionally you will want to call the same function multiple times, but with -different inputs, without caring about the return data but to check if any call -throws an error (sometimes not even that). This is where async.each is useful. -For example, the following will make three calls using the values in the array: - - var http = require('http') - , async = require('async'); - - async.each(['cat', 'meerkat', 'penguin'], function(item, done){ - var opts = { - hostname: 'http://httpbin.org', - path: '/post', - method: 'POST' - }; - var req = http.request(opts, function(res){ - res.on('data', function(chunk){ - }); - - res.on('end', function(){ - return done(); - }); - }); - - req.write(item); - req.end(); - }, - function(err){ - if (err) console.error(err); - }); - -Create a program that will receive two URLs as the first and second command-line -arguments. Then using `http.get`, create two GET requests to these URLs and -console.error any errors.