GScript > Java (pt. 3)

Here is how you sum up an array of integers in java:

  int[] values = ...
  int sum = 0;
  for( value : values ) {
    sum += value;
  }

Here is how you do it in gscript:

  var values = ...
  int sum = values.sum()

As a bonus, here is how you find the min, max and average:

  var min = values.min()
  var max = values.max()
  var average = values.average()

Not bad, eh?


One Comment on “GScript > Java (pt. 3)”

  1. Dev says:

    What is the advantage of *.gs files of rule studio? How it is differing with .java files?


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s