User loginNavigation 
Function Readability & UnderstandabilityTwo versions of the same function in JavaScript because its a language that supports both the functional and imperative style. The function accepts any number of arrays as arguments, and outputs the permutations of the values so (['a', 'b'],['1', '2']) becomes [['a', '1'], ['a', '2'], ['b', '1'], ['b', '2']]: function permutations1(x) { return x.reduce(function(a0, v0) { return a0.reduce(function(a1, v1) { return a1.concat(v0.map(function(v2) { return v1.concat([v2]); })); }, []); }, [[]]); } function permutations2(x) { var a = [[]]; for (var i = 0; i < x.length; ++i) { var b = []; for (var j = 0; j < a.length; ++j) { for (var k = 0; k < x[i].length; ++k) { b.push(a[j].concat([x[i][k]])); } } a = b; } return a; } Which do you find easier to read and understand, and if you find one easier, what do you think the reasons are? By Keean Schupke at 20141219 13:23  LtU Forum  previous forum topic  next forum topic  other blogs  9790 reads

Browse archives
Active forum topics 
Recent comments
13 weeks 3 days ago
13 weeks 3 days ago
13 weeks 3 days ago
35 weeks 4 days ago
39 weeks 6 days ago
41 weeks 3 days ago
41 weeks 3 days ago
44 weeks 1 day ago
48 weeks 5 days ago
48 weeks 6 days ago