CFLib.org – Common Function Library Project

ListAggregate(list[, delim])

Last updated March 25, 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;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson