Whatever message this page gives is out now! Go check it out!
StructReduce(struct, function(result, key, value [,struct]), initialVal)Parameter | Req/Opt | Default | Description |
| struct | Required | The input struct. | |
| function | Required | Closure or a function reference that will be called for each of the iteration. The arguments passed to the callback are
| |
| initialVal | Optional | Initial value that will be used for the reduce operation. The type is any. |
<cfscript>
person=StructNew();
person = {fname="John", lname="Doe"};
ucaseStruct = structMap(person, function(key, value)
{
return ucase(value);
});
writeDump(ucaseStruct);
concatValues = structReduce(person, function(result, key, value)
{
result = result?:"";
result&= value & " ";
return result;
});
writeDump(concatValues);
</cfscript><cfscript>
myStruct=StructNew();
myStruct={a=1,b=2,c=3,d=4,e=5};
myReduce=myStruct.reduce(function(result,key,value){
return result+value;
},10);
WriteDump(myReduce); // Returns 25
</cfscript>