Skip to content

Instantly share code, notes, and snippets.

@ryanguill
Forked from linkmckinney/fizzcom.cfm
Created July 19, 2012 13:40
Show Gist options
  • Save ryanguill/3143962 to your computer and use it in GitHub Desktop.
Save ryanguill/3143962 to your computer and use it in GitHub Desktop.
fizzcom
<cfcomponent>
<cffunction name="processFizz" access="remote" returntype="String"><!--- no output --->
<cfargument name="input" type="numeric"><!--- no required --->
<cfset var local = structNew()/>
<cfset local.result = ''/>
<cfif arguments.input MOD 3 EQ 0 AND arguments.input MOD 5 EQ 0>
<cfset local.result = 'fizzbuzz'/><!--- you aren't concatonating, so why not just return right here? --->
<cfelseif arguments.input MOD 5 EQ 0>
<cfset local.result = 'buzz'/><!--- and here --->
<cfelseif arguments.input MOD 3 EQ 0 >
<cfset local.result = 'fizz'/><!--- and here --->
<cfelse>
<cfset local.result = arguments.input/><!--- and if you did that, you dont need an else... --->
</cfif>
<cfreturn local.result /><!--- you just return arguments.input here --->
</cffunction>
</cfcomponent>
<cfloop from="1" to="100" index="i">
<cfinvoke component="fizzCom" method="processFizz" returnvariable="variables.result">
<cfinvokeargument name="input" value="#i#">
</cfinvoke>
<cfoutput>#variables.result#<br/></cfoutput><!--- your outputs should be outside of your loop, with this you are opening and closing 100 times --->
</cfloop>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment