Skip to content

Commit c881866

Browse files
Solve:forEachFilterIsNaN
1 parent 350f42a commit c881866

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+
배열 원소중 숫자인 원소만 뽑아 배열을 만드세요.
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.filter((item) => item === Number(item));
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: [1, 40, '라매', '개발자', 51.5, 'a', 88],
5+
answer: [1, 40, 51.5, 88],
6+
};
7+
8+
const test2 = {
9+
input: [1, 2, 3, '4', 5, '6'],
10+
answer: [1, 2, 3, 5],
11+
};
12+
13+
const test3 = {
14+
input: [-3, -2, -1, 0, 1, 2, 3],
15+
answer: [-3, -2, -1, 0, 1, 2, 3],
16+
};
17+
18+
describe('forEachFilterIsNaN', () => {
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)