Skip to content

Instantly share code, notes, and snippets.

@orangexception
Created October 26, 2012 19:32
Show Gist options
  • Save orangexception/3960946 to your computer and use it in GitHub Desktop.
Save orangexception/3960946 to your computer and use it in GitHub Desktop.
A Quick Refactor for Mike Henke
# A Quick Refactor for Mike Henke
<!--- Transforms a query of names into an oddly formatted string.
# Example
Query
`First` `Last`
Bradley Moore
Wayne Moore
Orange Exception
Output
`Bradley, Wayne Moore and Orange Exception`
--->
<cfset qMinorList= MinorList />
<cfif qMinorList.RecordCount EQ 1>
<cfset sMinorNames= qMinorList.First & " " & qMinorList.Last />
<cfelse>
<cfloop query= "qMinorList">
<!--- First Record --->
<cfif qMinorList.CurrentRow EQ 1>
<cfset sMinorNames= qMinorList.First />
<cfset sLastHold= TRIM( qMinorList.Last ) />
<!--- Middle Records --->
<cfelseif qMinorList.CurrentRow LT qMinorList.RecordCount>
<cfif Compare( sLastHold , qMinorList.Last ) EQ 0>
<cfset sMinorNames&= ", " & qMinorList.First />
<cfelse>
<cfset sMinorNames&= " " & sLastHold & "," />
<cfset sLastHold= TRIM( qMinorList.Last ) />
</cfif>
<!--- Last Record --->
<cfelse>
<cfif Compare( sLastHold , qMinorList.Last ) NEQ 0>
<cfset sMinorNames&= " " & sLastHold />
</cfif>
<cfset sMinorNames&= " and " & qMinorList.First & " " & qMinorList.Last />
</cfif>
</cfloop>
</cfif>
<cfset minornames= sMinorNames />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment