CFLib.org – Common Function Library Project

countTrueBoolKeysInStruct(strc)

Last updated September 16, 2012

author

Alan McCollough

Version: 1 | Requires: CF8 | Library: UtilityLib

Description:
You supply a structure filled with keys that are boolean values, and I will return a number of how many keys were boolean values that evaluated to true.

Return Values:
Returns a numeric value that is the number of boolean TRUE values found in the struct

Example:

<cfscript>
loc={};
loc.lorem="true";
loc.ipsum="false";
loc.dolor="true";
</cfscript>
result is 2: #countTrueBoolKeysInStruct(loc)#

Parameters:

Name Description Required
strc A struct to count positive booleans Yes

Full UDF Source:

/**
 * I loop through a struct that contains keys set to boolean values and return count of how many keys evaluate true.
 * v0.1 by Alan McCollough
 * v1.0 by Adam Cameron.  VARing
 * 
 * @param strc 	 A struct to count positive booleans (Required)
 * @return Returns a numeric value that is the number of boolean TRUE values found in the struct 
 * @author Alan McCollough (amccollough@anthc.org) 
 * @version 1.0, September 16, 2012 
 */
function countTrueBoolKeysInStruct(strc){
	var x = 0;
	var i = 0;
	for(i in strc) {
		if (isBoolean(strc[i]) && strc[i]){
			x++;
		}
	};
	return x;
};
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