-
Notifications
You must be signed in to change notification settings - Fork 4
[moonjonghoo]25.01.02 #2
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
7012bff
8016fbe
98d2c33
8dd6872
b56338e
d762df2
2c5fac8
6b3eef2
8302cf8
b1daddd
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,4 @@ | ||
| function solution(line) { | ||
| var answer = []; | ||
| return answer; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| function solution(arr, divisor) { | ||
| var answer = []; | ||
| for (let i = 0; i < arr.length; i++) { | ||
| if (arr[i] % divisor === 0) { | ||
| answer.push(arr[i]); | ||
| } | ||
| } | ||
| if (answer.length === 0) { | ||
| answer = [-1]; | ||
| } | ||
|
|
||
| answer.sort(function (a, b) { | ||
| return a - b; | ||
| }); | ||
|
|
||
| return answer; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| function solution(array, n) { | ||
| var answer = 0; | ||
| for (let i = 0; i < array.length; i++) { | ||
| if (array[i] === n) { | ||
| answer++; | ||
| } | ||
| } | ||
| return answer; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| function solution(strlist) { | ||
| var answer = []; | ||
| for (let i = 0; i < strlist.length; i++) { | ||
| answer.push(strlist[i].length); | ||
| } | ||
|
Comment on lines
+3
to
+5
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. map 메서드를 사용하면 더 간결하게 구현하실 수 있으실 것 같아요! |
||
| return answer; | ||
| } | ||
|
|
||
| console.log(solution(["We", "are", "the", "world!"])); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| function solution(arr1, arr2) { | ||
| var answer = []; | ||
| for (let i = 0; i < arr1.length; i++) { | ||
| let minarr = []; | ||
| for (let j = 0; j < arr1[i].length; j++) { | ||
| minarr.push(arr1[i][j] + arr2[i][j]); | ||
| } | ||
| answer.push(minarr); | ||
| } | ||
| return answer; | ||
| } | ||
| console.log( | ||
| solution( | ||
| [ | ||
| [1, 2], | ||
| [2, 3], | ||
| ], | ||
| [ | ||
| [3, 4], | ||
| [5, 6], | ||
| ] | ||
| ) | ||
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| function solution(arr1, arr2) { | ||
| const newArr = []; | ||
|
|
||
| for (let i = 0; i < arr1.length; i++) { | ||
| let result = []; | ||
| for (let j = 0; j < arr2[0].length; j++) { | ||
| let elem = 0; | ||
| for (let k = 0; k < arr2.length; k++) { | ||
| // arr1[0].length도 가능. | ||
| elem += arr1[i][k] * arr2[k][j]; | ||
| } | ||
| result.push(elem); | ||
| } | ||
| newArr.push(result); | ||
| } | ||
| return newArr; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| function solution(arr) { | ||
| var answer = []; | ||
| if (arr.length === 1) { | ||
| answer = [-1]; | ||
| } else { | ||
| let min = Math.min(...arr); | ||
| for (let i = 0; i < arr.length; i++) { | ||
| if (arr[i] !== min) { | ||
| answer.push(arr[i]); | ||
| } | ||
| } | ||
|
Comment on lines
+7
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문 부분을 filter 메서드를 사용하면 더 간결하게 작성할 수 있을 것 같아요! |
||
| } | ||
| return answer; | ||
| } | ||
|
|
||
| solution([4, 3, 2, 1]); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| function solution(numbers, direction) { | ||
| var answer = []; | ||
| //배열내부에 위치를 변경시키는 방법 | ||
| for (let i = 0; i < numbers.length; i++) { | ||
| if (direction === "right") { | ||
| let start = numbers[numbers.length - 1]; | ||
| answer = numbers.slice(0, numbers.length - 1); | ||
| answer.unshift(start); | ||
| } | ||
| if (direction === "left") { | ||
| let start = numbers[0]; | ||
| answer = numbers.slice(1, numbers.length); | ||
| answer.push(start); | ||
| } | ||
| } | ||
|
|
||
| return answer; | ||
| } | ||
|
Comment on lines
+4
to
+18
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문으로 조건문을 감싼 이유가 있나요?
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. 그러네요 수정하겠습니다! |
||
|
|
||
| console.log(solution([1, 2, 3], "right")); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| function solution(numbers, num1, num2) { | ||
| var answer = []; | ||
| answer = numbers.slice(num1, num2 + 1); | ||
| return answer; | ||
| } | ||
|
|
||
| console.log(solution([1, 2, 3, 4, 5], 1, 3)); |
Uh oh!
There was an error while loading. Please reload this page.
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.
sort를 화살표 함수가 아닌 익명 함수로 표현하신 이유가 있나요? 단순히 궁금해서 질문드려요!
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.
가끔실수가나와서 익명함수로 표현했습니다 ㅎㅎ..