Skip to content

Commit 4c9f6b1

Browse files
LerryLerry
authored andcommitted
[solve] forEachReduce
1 parent ac0313e commit 4c9f6b1

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 설명
2+
3+
forEach 메소드를 사용해서 배열의 총 합을 출력하는 코드를 작성하세요
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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const { solution } = require('./solve');
2+
3+
const test1 = {
4+
input: [100, 10, 20, 40],
5+
answer: 170,
6+
};
7+
8+
const test2 = {
9+
input: [120, -20, -30, 0, 15],
10+
answer: 85,
11+
};
12+
13+
const test3 = {
14+
input: [-10, -20, -30],
15+
answer: -60,
16+
};
17+
18+
describe('forEachReduce', () => {
19+
test('test1', () => {
20+
expect(solution(test1.input)).toEqual(test1.answer);
21+
});
22+
test('test2: 음수가 포함된 계산', () => {
23+
expect(solution(test2.input)).toEqual(test2.answer);
24+
});
25+
test('test3: 음수만 존재하는 계산', () => {
26+
expect(solution(test3.input)).toEqual(test3.answer);
27+
});
28+
});

0 commit comments

Comments
 (0)