Breaking up into groups

423
1
03-11-2014 10:59 AM
deleted-user-yA_w_FC9FKe5
New Contributor III
I have a bunch of Divisions (DIVISIONNA) and I would like to create a function that will total all of them up and give a quick summary. 

The divisions can be any combination of a 100 different divisions.

North = 5
Sourth  = 10
SA = 3
FL = 12

Not sure if this is important but the divisions are string values.  Currently this is what I have and it just list them

        function sumTransactions(features) {
          var transTotal = 0;
          for (var x = 0; x < features.length; x++) {
            transTotal = transTotal + features.attributes["DIVISIONNA"];
          }
          return transTotal;
        }

I'm using the selectinbuffer function to gather my features and then this function to do some totals.
0 Kudos
1 Reply
JohnathanBarclay
Occasional Contributor
You can use parseInt() to convert the strings to integers:

function sumTransactions(features) {
  var transTotal = 0;
  for (var x = 0; x < features.length; x++) {
    transTotal = transTotal + parseInt(features.attributes["DIVISIONNA"]);
  }
  return transTotal;
}
0 Kudos