Created
July 21, 2019 19:04
-
-
Save yerassylad/0b4023112ec86b1cad9aea5596015902 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const factorial = require("./factorial"); | |
const c = (n, m) => { | |
return factorial(n) / (factorial(m) * factorial((n -m))); | |
} | |
// ________ | |
const factorial = num => { | |
if (num < 0) | |
return -1; | |
else if (num == 0) | |
return 1; | |
else { | |
return (num * factorial(num - 1)); | |
} | |
} | |
// ------------- | |
const c = require('./c'); | |
const getList = number => { | |
const line = number - 1; | |
let accum = [] | |
for (let i = 0; i <= line; i++) { | |
if (i < 6) { | |
accum.push(c(line, i)); | |
} | |
} | |
return accum; | |
} | |
const calculateList = list => list.reduce((acc, curr) => (acc + curr), 0); | |
console.log(-1, getList(-1), calculateList(getList(-1))); | |
console.log(0, getList(0), calculateList(getList(0))); | |
console.log(1, getList(1), calculateList(getList(1))); | |
console.log(2, getList(2), calculateList(getList(2))); | |
console.log(3, getList(3), calculateList(getList(3))); | |
console.log(4, getList(4), calculateList(getList(4))); | |
console.log(5, getList(5), calculateList(getList(5))); | |
console.log(6, getList(6), calculateList(getList(6))); | |
console.log(7, getList(7), calculateList(getList(7))); | |
console.log(8, getList(8), calculateList(getList(8))); | |
console.log(9, getList(9), calculateList(getList(9))); | |
console.log(10, getList(10), calculateList(getList(10))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment