2
votes
0answers
34 views

functional javascript - recursively walking a tree to build up a new one; could this be better factored as a reduce?

/** * recursively build a nested Backbone.Model or Backbone.Collection * from a deep JSON structure. * * undefined for regex values */ exports.modelify = function modelify (data) { if ...
1
vote
2answers
37 views

functional javascript - how could I generalize this code that correlates parallel async requests with their results?

/** * takes a list of componentIDs to load, relative to componentRoot * returns a promise to the map of (ComponentID -> componentCfg) */ function asyncLoadComponents (componentRoot, components) ...
3
votes
1answer
92 views

The eternal dilemma: bar.foo() or foo(bar)?

I was using foo(bar) as it's adopted for functional programming. console.log( join( map(function(row){ return row.join(" "); }, tablify( ...
1
vote
0answers
25 views

Is this code for getting the dependency tree of a file correct?

function dep_tree(graph,node,prev_deps){ return uniq(flatten(graph[node].map(function(child_node){ if (contains(prev_deps,child_node)) throw "Circular reference between ...
3
votes
1answer
111 views

Functional Sundaram's sieve

I wrote this Sundaram's sieve in Coffeescript to quickly generate prime numbers up to limit: sieve_sundaram = (limit) -> numbers = (n for n in [3...limit+1] by 2) half = limit / 2 ...
6
votes
3answers
186 views

Overusing JavaScript closures?

I've finally gotten around to learning Lisp/functional programming. However, what I've noticed is that I'm trying to bring ideas back into JavaScript. Example Before var myPlacemark, ...
1
vote
1answer
125 views

Solution to 99 lisp problems: P08 with functional javascript

Solution to 99 lisp problems: P08, with functional javascript If a list contains repeated elements they should be replaced with a single copy of the element. The order of the elements should not ...
5
votes
1answer
318 views

Optimizing and consolidating a big jQuery function

I understand this is a very vague question and a lot of code to look over. My question is basically: I have all these functions that work together to create functionality on a page: is the structure ...
5
votes
1answer
212 views

Project Euler question 2 in CoffeeScript

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms. fib = (x) -> return 0 if x == 0 return 1 if x == 1 ...
3
votes
3answers
121 views

Functional way to write this code

I have a pan control that look like this: Pretty standard Google Mapsish controls, IMO. When the user clicks in the top 3rd of the control, it should pan up (deltaY = +1); right third means it ...
0
votes
1answer
130 views

Javascript: Replacing a for loop that iterates over an array with the functional programming equivalent

Player.prototype.d2 = function(ratingList, rdList) { var tempSum = 0; for (var i = 0; i < ratingList.length; i++) { var tempE = this.e(ratingList[i], rdList[i]); tempSum += ...