Skip to content

Instantly share code, notes, and snippets.

@MichaelMartinez
Created March 11, 2012 02:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MichaelMartinez/2014548 to your computer and use it in GitHub Desktop.
Save MichaelMartinez/2014548 to your computer and use it in GitHub Desktop.
CoffeeScript StrCalc Kata Implementation
window.StrCalc = class StrCalc
constructor: (myStr = 0) ->
if myStr is '0' or myStr is 0
@firstNum = 0
else
@parseMyNum myStr
parseMyNum: (myStr) ->
pattern = /(\d)+.*?(\d*)/gm
result = myStr.match pattern
@firstNum = parseInt result[0]
@secondNum = parseInt result[1]
@thirdNum = parseInt result[2]
@add()
add: ->
@total = @firstNum + @secondNum + @thirdNum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment