repl.it
@bearbearmo/

sequence writer - complex

Nodejs

No description

fork
loading
Files
  • index.js
  • Packager files
  • package-lock.json
index.js
1
2
3
4
5
6
7
8
9
10
let input = require("readline-sync").question("what's the nth term").split(" + ")
for (let n = 1; n <= 20; n++) {
  let s = 0;
  for (let i of input) {
    if(i.includes("^")) s += Math.pow(n, parseFloat(i.split("^")[1])) * (Number.isNaN(parseFloat(i.split("n")[0])) ? parseFloat(i.split("n")[0] + "1") : parseFloat(i.split("n")[0]));
    else if(i.includes("n")) s += n * (Number.isNaN(parseFloat(i.split("n")[0])) ? parseFloat(i.split("n")[0] + "1") : parseFloat(i.split("n")[0]));
    else s += parseFloat(i);
  }
  console.log(s + ", ");
}
?