The transition to NetApp MS Azure AD B2C is complete. If you missed the pre-registration, you will be invited to reigister at next log in.
Please note that access to your NetApp data may take up to 1 hour.
To learn more, read the FAQ and watch the video.
Need assistance? Complete this form and select “Registration Issue” as the Feedback Category.

Active IQ Unified Manager Discussions

WFA Function - Sum of an Array Elements

sheelnidhig

Hello,

I am trying to write a function which will sum all the Elements in an array...

def arrayElementSum(str)

{

          String[] splitArray = str.split(",");

          for(i=0; i<splitArray.length; i++) {

                    (int)myTotal += splitArray[i];

          }

          return myTotal;

}

This function is not working, can someone please have a look at it and see whats wrong init.

,Sheel

4 REPLIES 4

rkiran

Try this:

def arrayElementSum(str)

{

          String[] splitArray = str.split(",");

         int i = 0;

          int myTotal = 0;

          for (i = 0; i< splitArray.length; i++) {

                    myTotal += (int) splitArray[i];

          }

          return myTotal;

}

sheelnidhig

Hello,

I tried it but when testing it get the following:

Expression: - arrayElementSum("10")

Result: - 0class java.lang.Integer

Expression:- arrayElementSum("10,10")

Result: - 0class java.lang.Integerclass java.lang.Integer

Any Idea, how can we solve this.

,Sheel

rkiran

Which WFA version are you using ? The function code which I pasted earlier is working on my WFA server version 2.2.1.0.0RC1.

You can try using Integer.parseInt instead of casting to int while adding the myTotal.

sheelnidhig

Thanks it worked for me,

Announcements
NetApp on Discord Image

We're on Discord, are you?

Live Chat, Watch Parties, and More!

Explore Banner

Meet Explore, NetApp’s digital sales platform

Engage digitally throughout the sales process, from product discovery to configuration, and handle all your post-purchase needs.

NetApp Insights to Action
I2A Banner
Public