-
-
Save ryanguill/3143962 to your computer and use it in GitHub Desktop.
fizzcom
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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