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  6935 reads

Browse archivesActive forum topics 
Recent comments
3 hours 54 min ago
3 hours 54 min ago
4 hours 6 min ago
10 hours 12 min ago
10 hours 49 min ago
10 hours 56 min ago
14 hours 3 min ago
16 hours 47 min ago
18 hours 4 min ago
18 hours 41 min ago