Catalan numbers/Pascal's triangle: Difference between revisions

→‎ES6 JavaScript: Functional (distinguishing between first N element of series and Nth distinct Catalan number)
m (→‎ES6 JavaScript: Deleted one unused generic function)
(→‎ES6 JavaScript: Functional (distinguishing between first N element of series and Nth distinct Catalan number))
Line 691:
// CATALAN
 
// catalancatalanSeries :: Int -> [Int]
let catalancatalanSeries = n => {
let alternate = xs => xs.reduce(
(a, x, i) => i % 2 === 0 ? a.concat([x]) : a, []
Line 698:
diff = xs => xs.length > 1 ? xs[0] - xs[1] : xs[0];
 
return tail(alternate(pascal((n + 1) * 2))
.map((xs, i) => diff(drop(i, xs))));
}
 
Line 742:
}
 
// drop :: Int -> [a] -> [a]
// Int -> String -> String
let drop = (n, xs) => xs.slice(n);
 
Line 749 ⟶ 748:
let tail = xs => xs.length ? xs.slice(1) : undefined;
 
return catalantail(15catalanSeries(16));
})();</lang>
 
9,659

edits