Skip to content

Commit b11c4eb

Browse files
authored
Merge pull request #164 from raccoon-ccoder/master
Solve: forEachFilter
2 parents 0001d6b + c881866 commit b11c4eb

File tree

6 files changed

+58
-0
lines changed

6 files changed

+58
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 설명
2+
3+
배열 원소중 40 이상인 수만 뽑아 배열을 만드세요.
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>=40);
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: [100, 10, 20, 40],
5+
answer: [100, 40],
6+
};
7+
8+
describe('forEachFilter', () => {
9+
test('test1', () => {
10+
expect(solution(test1.input)).toEqual(test1.answer);
11+
});
12+
});
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)