Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

js varargs and reduction in sheet workers

1599844039

Edited 1599844360
Marco G.
Pro
Sheet Author
Hey Sheet Hackers, Is there any particular reason why the following code does not work for sheet workers? var sumArgs = (...args) => {   return args.reduce((a, b) => {      return a + b;   }; }; In a character sheet where I am summing lots of things this would be really a helpful convenience function. Ofc the real life scenario is a bit more "complex" and also parses the values to int or assumes 0. Cheers, Marco
1599844282
GiGs
Pro
Sheet Author
API Scripter
You can use reduce like that in sheet workers. If the code above is your actual code, I notice this bit: (..args)  should be (...args)  If that's not your actual code, post the actual code and we'll figure out what's going wrong.
1599844382

Edited 1599844847
Marco G.
Pro
Sheet Author
Hey GiGs, yeah I noticed that one as well, it's actually a typo .
1599844772

Edited 1599844836
Marco G.
Pro
Sheet Author
GiGs said: You can use reduce like that in sheet workers. If the code above is your actual code, I notice this bit: (..args)  should be (...args)  If that's not your actual code, post the actual code and we'll figure out what's going wrong. Rubberduck debugging did it for me. Thanks. (maybe I should learn to properly write javascript at some point...)