Permalink
Browse files

Fixed mutation of first file's stats

  • Loading branch information...
tj committed Aug 3, 2011
1 parent 24ec72b commit fedd78ff38a6323bb3f05bdd9a81866d16b43b4a
Showing with 4 additions and 8 deletions.
  1. +4 −8 bin/stats
View
@@ -92,20 +92,16 @@ while (args.length) {
// process
-var totals;
+var totals = {};
stats.find(paths, function(err, files){
var pending = files.length;
files.forEach(function(file){
fs.readFile(file, 'utf8', function(err, str){
if (err) throw err;
statistics[file] = stats.parse(str, options);
- if (totals) {
- Object.keys(statistics[file]).forEach(function(key){
- totals[key] += statistics[file][key];
- });
- } else {
- totals = statistics[file];
- }
+ Object.keys(statistics[file]).forEach(function(key){
+ totals[key] = (totals[key] || 0) + statistics[file][key];
+ });
--pending || done();
});
});

0 comments on commit fedd78f

Please sign in to comment.