Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // recursive formula for factorial
- const factorial = (n = 0) => {
- return n === 0 ? 1 : n*factorial(n-1);
- }
- // https://en.wikipedia.org/wiki/Binomial_coefficient
- const binomial_coefficient = (n = 0, k = 0) => {
- return factorial(n)/factorial(k)/factorial(n-k);
- }
- // https://en.wikipedia.org/wiki/Pascal%27s_triangle#Formula
- const pascal = (N = 8) => {
- for(let i = 0; i < N; i++) {
- let line = "";
- for(let j = 0; j <= i; j++) {
- line += ` ${String(binomial_coefficient(i, j))}`;
- }
- console.log(line);
- }
- }
- N = parseInt(process.argv[2] || 8);
- pascal(N);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement