-
Notifications
You must be signed in to change notification settings - Fork 4
[JustDevRae] 25.01.02 #4
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
58dae09
remove smallest number / ไปฅ๎๏ฟฝ
JustDevRae d1ddf64
divisible numbers array / ไปฅ๎๏ฟฝ
JustDevRae 8d7fe56
duplicate number count / ๆนฒ๊ณ๏ฟฝ
JustDevRae d7f63b0
matrix addition / ไปฅ๎๏ฟฝ
JustDevRae 36b4d80
array element length / ๆนฒ๊ณ๏ฟฝ
JustDevRae bab0b85
rotate array / ๆนฒ๊ณ๏ฟฝ
JustDevRae c8b3d17
slice array / ๆนฒ๊ณ๏ฟฝ
JustDevRae ec04f07
array algorithm md file
JustDevRae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,190 @@ | ||
| # ๋ฐฐ์ด ์๊ณ ๋ฆฌ์ฆ & ์๊ฐ๋ณต์ก๋ ์ ๋ฆฌ | ||
|
|
||
| ## 1. ๋ฐฐ์ด ๊ด๋ จ ๋ด์ฅ ํจ์ | ||
|
|
||
| ### 1.1 map | ||
| - ์ค๋ช : ๊ฐ ์์์ ํจ์๋ฅผ ์ ์ฉํ์ฌ ์ ๋ฐฐ์ด์ ๋ง๋ญ๋๋ค. | ||
| - ์๊ฐ๋ณต์ก๋: O(n) | ||
| - ์์ ์ฝ๋: | ||
| ```javascript | ||
| const arr = [1, 2, 3]; | ||
| const doubled = arr.map(x => x * 2); | ||
| console.log(doubled); // [2, 4, 6] | ||
| ``` | ||
|
|
||
| ### 1.2 filter | ||
| - ์ค๋ช : ์กฐ๊ฑด์ ์ถฉ์กฑํ๋ ์์๋ง์ผ๋ก ์ ๋ฐฐ์ด์ ๋ง๋ญ๋๋ค. | ||
| - ์๊ฐ๋ณต์ก๋: O(n) | ||
| - ์์ ์ฝ๋: | ||
| ```javascript | ||
| const arr = [1, 2, 3, 4]; | ||
| const evens = arr.filter(x => x % 2 === 0); | ||
| console.log(evens); // [2, 4] | ||
| ``` | ||
|
|
||
| ### 1.3 reduce | ||
| - ์ค๋ช : ๋ฐฐ์ด์ ํ๋์ ๊ฐ์ผ๋ก ์ถ์ํฉ๋๋ค. | ||
| - ์๊ฐ๋ณต์ก๋: O(n) | ||
| - ์์ ์ฝ๋: | ||
| ```javascript | ||
| const arr = [1, 2, 3, 4]; | ||
| const sum = arr.reduce((acc, cur) => acc + cur, 0); | ||
| console.log(sum); // 10 | ||
| ``` | ||
|
|
||
| ### 1.4 forEach | ||
| - ์ค๋ช : ๋ฐฐ์ด์ ๊ฐ ์์์ ๋ํด ์ ๊ณต๋ ํจ์๋ฅผ ์คํํฉ๋๋ค. | ||
| - ์๊ฐ๋ณต์ก๋: O(n) | ||
| - ์์ ์ฝ๋: | ||
| ```javascript | ||
| const arr = [1, 2, 3]; | ||
| arr.forEach(x => console.log(x)); | ||
| ``` | ||
|
|
||
| ### 1.5 push | ||
| - ์ค๋ช : ๋ฐฐ์ด์ ๋์ ํ๋ ์ด์์ ์์๋ฅผ ์ถ๊ฐํฉ๋๋ค. | ||
| - ์๊ฐ๋ณต์ก๋: O(1) | ||
| - ์์ ์ฝ๋: | ||
| ```javascript | ||
| const arr = [1, 2, 3]; | ||
| arr.push(4); | ||
| console.log(arr); // [1, 2, 3, 4] | ||
| ``` | ||
|
|
||
| ### 1.6 pop | ||
| - ์ค๋ช : ๋ฐฐ์ด์ ๋ง์ง๋ง ์์๋ฅผ ์ ๊ฑฐํฉ๋๋ค. | ||
| - ์๊ฐ๋ณต์ก๋: O(1) | ||
| - ์์ ์ฝ๋: | ||
| ```javascript | ||
| const arr = [1, 2, 3, 4]; | ||
| arr.pop(); | ||
| console.log(arr); // [1, 2, 3] | ||
| ``` | ||
|
|
||
| ### 1.7 unshift | ||
| - ์ค๋ช : ๋ฐฐ์ด์ ์์ ๋ถ๋ถ์ ํ๋ ์ด์์ ์์๋ฅผ ์ถ๊ฐํฉ๋๋ค. | ||
| - ์๊ฐ๋ณต์ก๋: O(n) | ||
| - ์์ ์ฝ๋: | ||
| ```javascript | ||
| const arr = [1, 2, 3]; | ||
| arr.unshift(0); | ||
| console.log(arr); // [0, 1, 2, 3] | ||
| ``` | ||
|
|
||
| ### 1.8 shift | ||
| - ์ค๋ช : ๋ฐฐ์ด์ ์ฒซ ๋ฒ์งธ ์์๋ฅผ ์ ๊ฑฐํฉ๋๋ค. | ||
| - ์๊ฐ๋ณต์ก๋: O(n) | ||
| - ์์ ์ฝ๋: | ||
| ```javascript | ||
| const arr = [1, 2, 3]; | ||
| arr.shift(); | ||
| console.log(arr); // [2, 3] | ||
| ``` | ||
|
|
||
| ## 2. ๊ฒ์ ์๊ณ ๋ฆฌ์ฆ | ||
|
|
||
| ### 2.1 ์ ํ ๊ฒ์ | ||
| - ์ค๋ช : ๋ฐฐ์ด์ ๊ฐ ์์๋ฅผ ์์ฐจ์ ์ผ๋ก ํ์ธํ์ฌ ๋ชฉํ๊ฐ์ ์ฐพ์ต๋๋ค. | ||
| - ์๊ฐ๋ณต์ก๋: O(n) | ||
| - ์์ ์ฝ๋: | ||
| ```javascript | ||
| const arr = [1, 2, 3, 4, 5]; | ||
| console.log(arr.indexOf(3)); // 2 | ||
| console.log(arr.find(x => x > 3)); // 4 | ||
| ``` | ||
|
|
||
| ### 2.2 ์ด์ง ๊ฒ์ | ||
| - ์ค๋ช : ์ ๋ ฌ๋ ๋ฐฐ์ด์์ ์ค๊ฐ๊ฐ์ ๊ธฐ์ค์ผ๋ก ํ์ ๋ฒ์๋ฅผ ์ขํ๊ฐ๋ฉฐ ๋ชฉํ๊ฐ์ ์ฐพ์ต๋๋ค. | ||
| - ์๊ฐ๋ณต์ก๋: O(log n) | ||
| - ์์ ์ฝ๋: | ||
| ```javascript | ||
| function binarySearch(arr, target) { | ||
| let left = 0; | ||
| let right = arr.length - 1; | ||
| while (left <= right) { | ||
| const mid = Math.floor((left + right) / 2); | ||
| if (arr[mid] === target) return mid; | ||
| if (arr[mid] < target) left = mid + 1; | ||
| else right = mid - 1; | ||
| } | ||
| return -1; | ||
| } | ||
|
|
||
| const arr = [1, 2, 3, 4, 5]; | ||
| console.log(binarySearch(arr, 3)); // 2 | ||
| ``` | ||
|
|
||
| ## 3. ์ ๋ ฌ ์๊ณ ๋ฆฌ์ฆ | ||
|
|
||
| ### 3.1 ๊ธฐ๋ณธ ์ ๋ ฌ | ||
| - ์ค๋ช : ๋ฐฐ์ด์ ์์๋ฅผ ์ฌ์ ์ ๋๋ ์ฌ์ฉ์ ์ ์ ์์์ ๋ฐ๋ผ ์ ๋ ฌํฉ๋๋ค. | ||
| - ์๊ฐ๋ณต์ก๋: ํ๊ท O(n log n) | ||
| - ์์ ์ฝ๋: | ||
| ```javascript | ||
| const arr = [4, 2, 5, 1, 3]; | ||
| arr.sort((a, b) => a - b); // [1, 2, 3, 4, 5] | ||
| ``` | ||
|
|
||
| ### 3.2 ๋ฒ๋ธ ์ ๋ ฌ | ||
| - ์ค๋ช : ์ธ์ ํ ๋ ์์๋ฅผ ๋น๊ตํ์ฌ ์ ๋ ฌํฉ๋๋ค. | ||
| - ์๊ฐ๋ณต์ก๋: O(n^2) | ||
| - ์์ ์ฝ๋: | ||
| ```javascript | ||
| function bubbleSort(arr) { | ||
| for (let i = 0; i < arr.length; i++) { | ||
| for (let j = 0; j < arr.length - i - 1; j++) { | ||
| if (arr[j] > arr[j + 1]) { | ||
| [arr[j], arr[j + 1]] = [arr[j + 1], arr[j]]; | ||
| } | ||
| } | ||
| } | ||
| return arr; | ||
| } | ||
|
|
||
| const arr = [4, 2, 5, 1, 3]; | ||
| console.log(bubbleSort(arr)); // [1, 2, 3, 4, 5] | ||
| ``` | ||
|
|
||
| ### 3.3 ํต ์ ๋ ฌ | ||
| - ์ค๋ช : ๊ธฐ์ค ๊ฐ์ ์ ํ๊ณ ์ด๋ฅผ ๊ธฐ์ค์ผ๋ก ๋ฐฐ์ด์ ๋ถํ ํ์ฌ ์ ๋ ฌํฉ๋๋ค. | ||
| - ์๊ฐ๋ณต์ก๋: ํ๊ท O(n log n) | ||
| - ์์ ์ฝ๋: | ||
| ```javascript | ||
| function quickSort(arr) { | ||
| if (arr.length <= 1) return arr; | ||
| const pivot = arr[0]; | ||
| const left = arr.slice(1).filter(x => x < pivot); | ||
| const right = arr.slice(1).filter(x => x >= pivot); | ||
| return [...quickSort(left), pivot, ...quickSort(right)]; | ||
| } | ||
|
|
||
| const arr = [4, 2, 5, 1, 3]; | ||
| console.log(quickSort(arr)); // [1, 2, 3, 4, 5] | ||
| ``` | ||
|
|
||
| ### 3.4 ๋ณํฉ ์ ๋ ฌ | ||
| - ์ค๋ช : ๋ฐฐ์ด์ ๋ฐ์ผ๋ก ๋๋์ด ์ ๋ ฌํ ๋ค ๋ณํฉํฉ๋๋ค. | ||
| - ์๊ฐ๋ณต์ก๋: O(n log n) | ||
| - ์์ ์ฝ๋: | ||
| ```javascript | ||
| function mergeSort(arr) { | ||
| if (arr.length <= 1) return arr; | ||
| const mid = Math.floor(arr.length / 2); | ||
| const left = mergeSort(arr.slice(0, mid)); | ||
| const right = mergeSort(arr.slice(mid)); | ||
|
|
||
| function merge(left, right) { | ||
| const result = []; | ||
| while (left.length && right.length) { | ||
| if (left[0] < right[0]) result.push(left.shift()); | ||
| else result.push(right.shift()); | ||
| } | ||
| return [...result, ...left, ...right]; | ||
| } | ||
|
|
||
| return merge(left, right); | ||
| } | ||
|
|
||
| const arr = [4, 2, 5, 1, 3]; | ||
| console.log(mergeSort(arr)); // [1, 2, 3, 4, 5] | ||
| ``` |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| function solution(strlist) { | ||
| var answer = []; | ||
| answer = strlist.map((str) => str.length); | ||
|
|
||
| return answer; | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| function solution(arr, divisor) { | ||
| var answer = []; | ||
|
|
||
| answer = arr.filter((element) => element % divisor === 0); | ||
| answer.sort((a, b) => a - b); | ||
|
|
||
| if (answer.length === 0) answer.push(-1); | ||
|
|
||
| return answer; | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| function solution(array, n) { | ||
| var answer = 0; | ||
| answer = array.filter((el) => el === n); | ||
|
|
||
| return answer.length; | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| function solution(arr1, arr2) { | ||
| var answer = [[]]; | ||
|
|
||
| for (let i = 0; i < arr1.length; i++) { | ||
| answer[i] = []; | ||
| for (let j = 0; j < arr1[i].length; j++) { | ||
| answer[i][j] = arr1[i][j] + arr2[i][j]; | ||
| } | ||
| } | ||
|
|
||
| return answer; | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| function solution(arr) { | ||
| var answer = []; | ||
| const minValue = Math.min(...arr); | ||
| answer = arr.filter((element) => element > minValue); | ||
| if (answer.length === 0) answer.push(-1); | ||
|
|
||
| return answer; | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| function solution(numbers, direction) { | ||
| var answer = []; | ||
|
|
||
| if (direction == "left") { | ||
| numbers.push(numbers.shift()); | ||
| } | ||
|
|
||
| if (direction == "right") { | ||
| numbers.unshift(numbers.pop()); | ||
| } | ||
|
|
||
| return (answer = numbers); | ||
| } | ||
|
Comment on lines
+11
to
+13
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. ์๋ฏธ๋ฅผ ํด์ํ์ง ๋ชปํด ์ฐพ์๋ณด๋ ๊ฐ์ ๋ณต์ฌํ ํ ๋ฆฌํดํ๋ ๊ฑฐ์๊ตฐ์ฌ..! ๋ฐฐ์๊ฐ๋๋ค ๐ |
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| function solution(numbers, num1, num2) { | ||
| var answer = []; | ||
|
|
||
| return (answer = numbers.slice(num1, num2 + 1)); | ||
| } |
Oops, something went wrong.
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.
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.
ํ ์ค๋ก ์ค์ด๋ฉด ๋ ๊ฐ๊ฒฐํด์ง ์ ์์ ๊ฑฐ ๊ฐ์์!