Skip to content

Instantly share code, notes, and snippets.

@thekarel
Created November 1, 2013 16:08
Show Gist options
  • Save thekarel/7267656 to your computer and use it in GitHub Desktop.
Save thekarel/7267656 to your computer and use it in GitHub Desktop.
A helper function that can add (sum) strings and numbers AS NUMBERS, ie. "1"+2 will return 3 and not "12". Requires _
var sumAny = function() {
var sum = 0;
_.each(arguments, function(arg) {
var _num;
_num = parseInt(arg);
if (!isNaN(_num)) sum += _num;
});
return sum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment