CFLib.org – Common Function Library Project

ListAggregate(list[, delim])

Last updated March 26, 2002

author

Jesse Monson

Version: 1 | Requires: CF5 | Library: MathLib

Description:
Pass in any list of numbers and an optional delimiter set ("," is default) and it returns a list of the positional summations of that list. This function is great for financial numbers, time sensitive numbers or any order specific numbers.

Return Values:
Returns a string.

Example:

<cfset numbers = "1,2,3,4,5">
<cfset alphanum = "x;y;z;5;5;5;n">

<cfoutput>
#listAggregate(numbers)#<BR>
#listAggregate(alphanum,";")#
</cfoutput>

Parameters:

Name Description Required
list List of values you want to return a summation sequence for. Yes
delim Delimiter used to separate list elements. Default is the comma. No

Full UDF Source:

/**
 * Turn a list of numbers into a summation sequence.
 * 
 * @param list      List of values you want to return a summation sequence for. 
 * @param delim      Delimiter used to separate list elements.  Default is the comma. 
 * @return Returns a string. 
 * @author Jesse Monson (jesse@ixstudios.com) 
 * @version 1, March 25, 2002 
 */
function listAggregate(list) {
  var a=1;
  var sum=0;
  var sumList="";
  var delims=",";
  if (arrayLen(arguments) gte 2) {
    delims = arguments[2];
  }
    for ( ;a lte listLen(list,delims);a=a+1) {
      sum = sum + val(listGetAt(list,a,delims));
      sumList = ListAppend(sumList,sum,delims);
    }
  return sumList;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson