-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-1.js
68 lines (51 loc) · 1.93 KB
/
test-1.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// 1. 아래 코드의 의미를 설명하고 ES6의 functional programming을 활용해서 변경하세요.
// 수입의 부가세와, 수입의 합을 구하는 문제입니다.
const incomes = [1000, 2000, 3000, 4000];
const add = (accumulator, income) =>
accumulator + (typeof income !== 'number' ? 0 : income);
const division = income => (typeof income !== 'number' ? 0 : income / 11);
const vats = incomes =>
Array.isArray(incomes) ? incomes.map(division) : 'Not an array';
const price = incomes =>
Array.isArray(incomes) ? incomes.reduce(add, 0) : 'Not an array';
// 테스트
log(`=======================================================================`);
console.group(`Array 인 경우`);
log('[]: ', vats([]));
log('[1000, 2000, 3000, 4000]: ', vats([1000, 2000, 3000, 4000]));
log('[`1000`, `2000`, `3000`, `4000`]', vats([`1000`, `2000`, `3000`, `4000`]));
log(
`[false, undefined, 'string', {}]: `,
vats([false, undefined, 'string', {}])
);
console.groupEnd(`Array 인 경우`);
console.group(`Array 가 아닌 경우: `);
log(`{}: `, vats({}));
log(`1: `, vats(1));
log(`String: `, vats('String'));
log(`true: `, vats(true));
log(`undifined: `, vats(undefined));
console.groupEnd(`Array 가 아닌 경우: `);
log(`=======================================================================`);
console.group(`Array 인 경우`);
log('[]: ', price([]));
log('[1000, 2000, 3000, 4000]: ', price([1000, 2000, 3000, 4000]));
log(
'[`1000`, `2000`, `3000`, `4000`]',
price([`1000`, `2000`, `3000`, `4000`])
);
log(
`[false, undefined, 'string', {}]: `,
price([false, undefined, 'string', {}])
);
console.groupEnd(`Array 인 경우`);
console.group(`Array 가 아닌 경우: `);
log(`{}: `, price({}));
log(`1: `, price(1));
log(`String: `, price('String'));
log(`true: `, price(true));
log(`undifined: `, price(undefined));
console.groupEnd(`Array 가 아닌 경우: `);
function log(message, test = ``) {
console.log(message, test);
}