Wednesday, February 2, 2011: CoffeeScripting @ Code Jom « from the old blog archive »
I prepared for the final round by familiarizing myself with CoffeeScript. I made a simple mashup webapp called Crew Standings in CoffeeScript and using jQuery and YQL.
Because I planned it a bit wrong and went on working on the main scope, things got messed up when I create functions as sometimes it use the variables outside the function's scope (because I used a variable name outside that scope.
I couldn't do some questions that is based on some algorithm, where some others would be able to do it easily. For example, I was a bit too excited to be able to do the knapsack question.
price[p + '-' + m] = ......
But that looked ugly and less straightforward than built-in fixed multidimensional arrays like in C where you can
However, I did it. My team got the first place for the student level.
I ported the last year's library to CoffeeScript, so that I don't have to learn all the new set of functions.
I used a simple hack for forcing functions into the global scope
(-> # force global scope @print = (x...) -> sys.print y + '\n' for y in x ).call null
Anything that got added to
this will be added to the global scope, thanks to CoffeeScript,
this.name can be called
@name, so the above code added
Here is the full library script:
And a small example:
require './LIBRARY' for testcase in [1..scanNumber()] n = scanNumber() print (n * (n + 1)) / 2