Posted
about 13 years
ago
by
chris
isn't this more simple and functional?
function sum (array) { return array.reduce(function (a, b) { return a + b; })}
sum([1,2,3])
|
Posted
about 13 years
ago
by
Rafal
@pabrams: thanks. I've modified the function to make it more readable and got rid of most lint warnings. Updated code available on github (https://raw.github.com/kvz/phpjs/master/functions/var/empty.js)
|
Posted
about 13 years
ago
by
pabrams
Hi, for the first two js lint issues, try some carriage returns. Line #26 will also be much easier to read, especially if you format it nicely. Each new line after if (mixed_var === "" could start with a constant number of tabs and then ||
|
Posted
about 13 years
ago
by
Brett Zamir
@David: Thanks for the fix with the missing userdata argument. I changed it a bit to check for arguments.length (number of arguments passed), since otherwise, it won't allow explicit passing of "undefined" as an argument. I also added support for
|
Posted
about 13 years
ago
by
kneesspal
|
Posted
about 13 years
ago
by
David
Line 21 doesn't make any sense, you are only passing userdata to the function, and userdata is undefined. Line 21 should be:
eval(funcname + '(array[key] , key)');
|
Posted
about 13 years
ago
by
Mike
I found bug with count of parameters for this function. So if we set over than 2 arguments - function returns empty object.
You can test own example with colors on this page.
|
Posted
about 13 years
ago
by
Guergenug
|
Posted
about 13 years
ago
by
Brett Zamir
@Click Button Publishing: Glad to hear it is working for you! (I'm trying to help catch up on old messages one-by-one.)
|
Posted
about 13 years
ago
by
Brett Zamir
@Kaushik: Glad to hear it is helpful--thanks for the feedback!
|