Maximum triangle path sum: Difference between revisions
→Functional (ES5)
Line 720:
// (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d]
function zipWith3(f, xs, ys, zs) {
return zs.length ? [f(xs[0
zipWith3(f, xs.slice(1), ys.slice(1), zs.slice(1))) : [];
}
return foldr1(
function (xs, ys) {
Line 732 ⟶ 730:
return x + (y < z ? z : y);
},
xs, ys, ys.slice(1) // item above, and larger of two below
);
}, [
|