Merged
Conversation
unn04012
reviewed
Jan 5, 2025
Comment on lines
+2
to
+3
| var answer = []; | ||
| answer = strlist.map((str) => str.length); |
Collaborator
There was a problem hiding this comment.
한 줄로 줄이면 더 간결해질 수 있을 거 같아요!
const answer = strlist.map((str) => str.length);
unn04012
reviewed
Jan 5, 2025
Comment on lines
+11
to
+13
|
|
||
| return (answer = numbers); | ||
| } |
Collaborator
There was a problem hiding this comment.
의미를 해석하지 못해 찾아보니 값을 복사한 후 리턴하는 거였군여..! 배워갑니다 👍
bona1122
pushed a commit
to bona1122/AlgorithmStudy
that referenced
this pull request
Jan 9, 2025
[JustDevRae] 25.01.02
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📌 푼 문제
📝 간단한 풀이 과정
배열 자르기
slice를 사용해 매개변수로 받은 num1 위치부터 num + 2 위치 이전까지의 해당하는 값들을 담은 배열을 반환하도록 했습니다.
배열 원소의 길이
map을 사용해 문자열 배열의 각 원소를 순회하면서 각 문자열의 길이를 계산한 결과를 새로운 배열로 반환하도록 했습니다.
배열 회전시키기
조건이 left일 때는 shift로 배열의 맨 앞의 값을 꺼내어 push로 배열의 마지막 인덱스에 값을 넣도록 했고, right일 때는 pop으로 꺼낸 배열의 마지막 요소 값을 unshift로 맨 앞에 넣도록 했습니다.
중복된 숫자 갯수
filter 메서드를 사용해 n에 해당하는 값들만 담긴 배열을 생성하고, 그 배열의 길이를 반환하도록 했습니다.
제일 작은 수 제거하기
Math.min()과 스프레드 문법을 사용해 배열의 최소값 값을 구하고, 이후 filter 메서드를 사용해 최소값보다 큰 요소들을 담은 배열을 생성하도록 했습니다.
만약 반환된 배열의 길이가 0일 경우 push를 사용해 빈배열에 -1을 넣어 반환하도록 했습니다.
행렬의 덧셈
이중 for문을 사용해 문제를 풀었습니다. 처음에 코드를 실행했을 때는 자꾸 에러가 발생해 뭐가 문제인지 몰라서 헤맸습니다. vscode로 디버깅 돌리면서 확인해보니 처음
var answer = [[]];에 빈 배열 하나만 정의되어 있어서 없는 배열에 접근하여 값을 할당하려고 하니 에러가 발생한것이였습니다. 그래서 첫번째 for문에 i번째 요소를 빈 배열로 초기화해서 해결했습니다.나누어 떨어지는 숫자 배열
filter메서드로 각 요소를 순회하면서 divisor값의 나머지가 0인 값들만 담은 배열을 반환하고, 이후 반환된 배열을 sort로 오름차순으로 정렬했습니다. 만약 배열이 빈값이라면 빈 배열에 push로 -1을 넣어 반환하도록 했습니다.
ps. 고급 문제들은 답을 봤는데도 이해가 잘 안되서 다시 풀고 정리해서 issue에 올리겠습니다.