문제
8393번: 합
n이 주어졌을 때, 1부터 n까지 합을 구하는 프로그램을 작성하시오.
www.acmicpc.net
정답
let fs = require("fs");
let filePath = process.platform === "linux" ? "/dev/stdin" : "test.txt";
let input = Number(fs.readFileSync(filePath).toString());
let answer = Array(input)
.fill(1)
.map((a, b) => a + b)
.reduce((a, b) => a + b);
console.log(answer);