I\'d like to sum the values of an object.
I\'m used to python where it would just be:
sample = { \'a\': 1 , \'b\': 2 , \'c\':3 };
summed = sum(sampl
Honestly, given our "modern times" I'd go with a functional programming approach whenever possible, like so:
const sumValues = (obj) => Object.keys(obj).reduce((acc, value) => acc + obj[value], 0);
Our accumulator acc, starting with a value of 0, is accumulating all looped values of our object. This has the added benefit of not depending on any internal or external variables; it's a constant function so it won't be accidentally overwritten... win for ES2015!