Skip to content

Commit b4af8b5

Browse files
authored
20251025 (#21)
* add: 중복 단어 제거(indexOf) * add: 큰 수 출력하기
1 parent cde6a35 commit b4af8b5

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// 1번 풀이 (시간복잡도 O(n^2))
2+
// function solution(str) {
3+
// let answer = [];
4+
5+
// for (const word of str) {
6+
// if (!answer.includes(word)) {
7+
// answer.push(word);
8+
// }
9+
// }
10+
11+
// return answer;
12+
// }
13+
14+
// 2번 풀이 (시간복잡도 O(n^2))
15+
function solution(s) {
16+
return s.filter((v, i) => s.indexOf(v) === i);
17+
}
18+
19+
console.log(solution(['good', 'time', 'good', 'time', 'student'])); // ['good', 'time', 'student']
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function solution(arr) {
2+
let answer = [arr[0]];
3+
4+
for (let i = 1; i < arr.length; i++) {
5+
if (arr[i - 1] < arr[i]) {
6+
answer.push(arr[i]);
7+
}
8+
}
9+
10+
return answer;
11+
}
12+
13+
console.log(solution([7, 3, 9, 5, 6, 12])); // [7, 9, 12]

0 commit comments

Comments
 (0)