Hacker News new | ask | show | jobs
by emehrkay 4128 days ago
My approach, in any language, would be to collect it in an array and sum (or concatenate) it at once.

    var values = [];
    values.push(phraseValue( result, queryData ));
    ...
    var value = values.reduce(function(prev, next) { return pre + next; });
I understand that COLLECTION.reduce may not be in all javascript implementations (or even in all languages), but that would be my first thought on how to handle that mess. Id probably even make it a function addAllOfTheseValues(result, queryData);

I also dislike direct string concatenation, I always try to use print type functions because it is easier to separate variables from text and spot potential errors. I'm happy that JS is getting this.