Last active
November 25, 2019 00:59
-
-
Save shinchit/02d3d8f356eb9976e39beafa594971d2 to your computer and use it in GitHub Desktop.
This file contains 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
"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