Skip to content

Instantly share code, notes, and snippets.

@shinchit
Last active November 25, 2019 00:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shinchit/02d3d8f356eb9976e39beafa594971d2 to your computer and use it in GitHub Desktop.
Save shinchit/02d3d8f356eb9976e39beafa594971d2 to your computer and use it in GitHub Desktop.
"use strict"
function Main(input) {
let lines = input.split('\n');
let A = lines[0].split(' ');
console.log(summation(A));
console.log(product(A));
}
function summation(a) {
const reducer = (accumulator, currentValue) => accumulator + parseInt(currentValue, 10);
return a.reduce(reducer, 0);
}
function product(a) {
const reducer = (accumulator, currentValue) => accumulator * currentValue;
return a.reduce(reducer);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
// This program is used on the command line.
// Usage:
// $ node recursion.js
// 1 2 3 4
// 10
// 24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment