Skip to content

Instantly share code, notes, and snippets.

@shinchit
Last active November 25, 2019 00:59
Embed
What would you like to do?
"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