CFLib.org – Common Function Library Project

ArrayReverse(InArray)

Last updated October 9, 2001

author

Raymond Simmons

Version: 1 | Requires: CF5 | Library: DataManipulationLib

Description:
Reverses the order of elements in a one-dimensional array. This function takes a one-dimensional array and returns a new one with the values from the first in reverse order.

Return Values:
Returna a new one dimensional array.

Example:

<CFSET Numbers = "1,2,3,4,5">
<CFSET NumbersArray = ListToArray(Numbers)>
<CFSET NumbersArray = ArrayReverse(NumbersArray)>

<CFLOOP INDEX="I" FROM="1" TO="#ArrayLen(NumbersArray)#">
<CFOUTPUT>
#NumbersArray[I]#<BR>
</CFOUTPUT>
</CFLOOP>

Parameters:

Name Description Required
InArray One-dimensional array to be reversed. Yes

Full UDF Source:

/**
 * Reverses the order of elements in a one-dimensional array.
 * 
 * @param InArray 	 One-dimensional array to be reversed. 
 * @return Returna a new one dimensional array. 
 * @author Raymond Simmons (raymond@terraincognita.com) 
 * @version 1.0, October 9, 2001 
 */
function ArrayReverse(inArray){
	var outArray = ArrayNew(1);
	var i=0;
        var j = 1;
	for (i=ArrayLen(inArray);i GT 0;i=i-1){
		outArray[j] = inArray[i];
		j = j + 1;
	}
	return outArray;
}
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