-
Notifications
You must be signed in to change notification settings - Fork 4
[tkddbs587] 25.01.02 #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8ed1f35
e0d87fe
dd9f21d
be9ad9f
437e305
0bf2154
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| function solution(numbers, num1, num2) { | ||
| return numbers.slice(num1, num2 + 1); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| function solution(arr1, arr2) { | ||
| let answer = []; | ||
|
|
||
| for (let i = 0; i < arr1.length; i++) { | ||
| let newRow = []; | ||
|
|
||
| for (let j = 0; j < arr1[i].length; j++) { | ||
| newRow.push(arr1[i][j] + arr2[i][j]); | ||
| } | ||
| answer.push(newRow); | ||
| } | ||
|
|
||
| return answer; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| function solution(arr) { | ||
| let minNum = Math.min(...arr); | ||
| for (let i = 0; i < arr.length; i++) { | ||
| if (arr[i] === minNum) { | ||
| arr.splice(i, 1); | ||
| if (arr.length === 0) { | ||
| arr.push(-1); | ||
| } | ||
| } | ||
| } | ||
| return arr; | ||
|
Comment on lines
+3
to
+11
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 지금도 좋지만, for문 내부에서 splice메서드를 사용하면 배열의 길이가 변해서 불필요한 계산이 발생할 수 있다고 생각합니다... filter를 사용하면 배열을 다시 생성하면서 최소값만 제외할 수 있어서, 이떄는 filter를 사용하는걸 추천합니다👍
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for문에서 splice 쓰면 정말 그렇겠네요 이런 방법이! 감사합니다 🤩 |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| function solution(numbers, direction) { | ||
| if (direction === "right") { | ||
| const lastElement = numbers.pop(); | ||
| numbers.unshift(lastElement); | ||
| } else if (direction === "left") { | ||
| const firstElement = numbers.shift(); | ||
| numbers.push(firstElement); | ||
| } | ||
|
|
||
| return numbers; | ||
| } |
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. filter메서드랑 sort메서드 사용해서 간단하게 처리하신것 같습니다👍👍 근데,성능테스트했을때는 딱히 차이는 안나긴 했습니다...
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오 sort() 까지 한곳에서 해결하고 삼항 연산자로 하니까 훨씬 간결해졌네요! 👍🏻 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| function solution(arr, divisor) { | ||
| let newArr = arr.filter((el) => el % divisor === 0); // 나누어 떨어지는 엘리먼트가 담긴 새 배열 반환 | ||
|
|
||
| // 나누어 떨어지는 엘리먼트 없으면 그냥 [-1] 반환 | ||
| if (newArr.length === 0) { | ||
| return [-1]; | ||
| } | ||
|
|
||
| return newArr.sort((a, b) => a - b); // 오름차순 정렬 | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| function solution(array, n) { | ||
| return array.filter((el) => el === n).length; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| function solution(strlist) { | ||
| return strlist.map((str) => str.length); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
지금도 잘 작동하지만, 가독성면에서 조금 떨어지는 이중 for문을 더 간결하게 할수 있는지 생각을 해봤는데, 이렇게
arr1.entries()과 push메서드를 사용하는 방법은 어떤가 생각해 봤습니다.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
와우,, 이렇게까지 해주시다니 코테 왕초보라 모르는 메서드들 너무 많아요 감사합니다 채연님!