Skip to content

Commit f69c079

Browse files
LerryLerry
authored andcommitted
[solve] reduceSum
1 parent 4c9f6b1 commit f69c079

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

Challenge/lerrybe/reduceSum/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# 문제제목
2+
3+
## 설명
4+
5+
reduce 메소드를 사용해서 배열의 모든 수의 합을 구하세요.
6+
7+
## Expected Output
8+
9+
106

Challenge/lerrybe/reduceSum/solve.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// write your codes
2+
function solution(inputArray) {
3+
return inputArray.reduce((prev, curr) => prev + curr);
4+
}
5+
6+
exports.solution = solution;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const { solution } = require('./solve');
2+
3+
const test1 = {
4+
input: [10, 3, 20, 5, 8, 60],
5+
answer: 106,
6+
};
7+
8+
describe('reduceSum', () => {
9+
test('test1', () => {
10+
expect(solution(test1.input)).toEqual(test1.answer);
11+
});
12+
});

0 commit comments

Comments
 (0)