Created
November 1, 2013 16:08
-
-
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 _
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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