stringReduce

This function iterates over every character in the string and executes the callback function to reduce the string to a single value.

stringReduce(string,callback,initialValue) → returns string

Member Function Syntax

string.reduce(callback, initialValue)

Argument Reference

string string
Required

Original input string.

callback any
Required

Closure or a function reference.

initialVal any

Initial value for the reduce operation.

Compatibility

Lucee:

Version 6+ This function will be added in Lucee 6. It is similar to other reduce functions, like arrayReduce().

Links more information about stringReduce

Examples
Sample code invoking the stringReduce function

Reduce the string to a single value.

letters="abcdef";
closure=function(inp1,inp2){return inp1 & inp2;}
writeOutput( StringReduce(letters,closure,"z") );

Expected Result: zabcdef

Reduce the string to a single value.

letters="abcdef";
closure=function(inp1,inp2){return inp1 & inp2;}
writeOutput( letters.reduce(closure,"z") );

Expected Result: zabcdef

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub