Skip to content

Commit fddf834

Browse files
committed
Create programmers_꼬리-문자열.txt
1 parent 1ba24d8 commit fddf834

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// filter()로 풀이
2+
function solution(str_list, ex) {
3+
// filter() 메서드를 사용하여 str_list 배열을 순회
4+
// !str.includes(ex)로 ex를 포함하지 않는 문자열을 필터링
5+
// 필터링된 문자열들을 join('') 메서드로 결합
6+
return str_list.filter((str) => !str.includes(ex)).join('');
7+
}
8+
9+
// for문으로 풀이
10+
function solution(str_list, ex) {
11+
var answer = '';
12+
// for문으로 str_list 배열을 돌면서
13+
for (let i = 0; i < str_list.length; i++) {
14+
// 만약 str_list의 인덱스가 ex를 포함하지 않는다면
15+
if (!str_list[i].includes(ex)) {
16+
// answer에 해당 인덱스를 넣어주기
17+
answer += str_list[i];
18+
}
19+
}
20+
21+
return answer;
22+
}
23+
24+
// reduce()로 풀이
25+
function solution(str_list, ex) {
26+
// 초기값을 빈 문자열 ''로 설정하여 문자를 덧붙일 수 있도록하고,
27+
// cur.includes(ex)를 통해 현재 요소 cur에 ex가 포함되어있다면, ''를 더하고,
28+
// 아니라면 cur를 더함
29+
return str_list.reduce((acc, cur) => acc + (cur.includes(ex) ? '' : cur), '')};

0 commit comments

Comments
 (0)