December 2011
4 posts
I hope that in this year to come, you make mistakes.
Because if you are making...
– Neil Gaiman (via drinkyourjuice)
4 tags
Backbone.JS Confustion
Backbone.js is a handy tool for organizing JavaScript in larger scale projects. It can be a lot to wrap your head around though, and I think a lot of the issue is that Backbone calls itself an “MVC” framework, when it really isn’t (or at least uses a very loose definition of that term) and has quite a few misnomers that make things confusing. Here are some of the tricky bits, and...
4 tags
Functional 12 Days of Christmas - Shorter Version
so, I still wanted to leave me previous example up, since I thought it gave a simple example of how to use the ever-so-handy reduce() function, but I just found out about python’s sum function, which does allow for a much shorter version:
sum(map(sum,map(lambda x: range(1, x+1),range(1,13))))
And, after having a flashback to algebra class, I did remember that you can calculate the sum of...
2 tags
The functional 12 days of Christmas
I was asked what the total of number of items in the 12 days of Christmas song was, so I decided to see if I could come up with a functional solution in python. I came up with this one-liner:
reduce(lambda x,y: x+y,reduce(lambda x, y: x+y, map(lambda x: range(1,1+x), range(1,13))))
which I thought was a nice solution, and proivdes a good example of functional programming practices and basic...