-
Notifications
You must be signed in to change notification settings - Fork 0
day32 re PR #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
Open
lgyn10
wants to merge
1
commit into
main
Choose a base branch
from
day32
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
day32 re PR #6
Changes from all commits
Commits
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,35 @@ | ||
| // https://school.programmers.co.kr/learn/courses/30/lessons/120890 | ||
|
|
||
| // 최초 코드 | ||
| const 가까운수 = (array: number[], n: number): number => { | ||
| array.sort(); | ||
| const absArr = array.map((v) => Math.abs(v - n)); | ||
| const closestVal = Math.min(...absArr); | ||
| const closestIdx = absArr.findIndex((v) => v === closestVal); | ||
| return array[closestIdx]; | ||
| }; | ||
|
|
||
| // 다른 사람 코드 | ||
| // sort() 메서드의 콜백함수 2가지 기준 정렬 적용 | ||
| const 가까운수2 = (array: number[], n: number): number => { | ||
| array.sort((a, b) => Math.abs(n - a) - Math.abs(n - b) || a - b); | ||
| return array[0]; | ||
| }; | ||
|
|
||
| // sort() 콜백 함수를 풀어서 작성 | ||
| const 가까운수3 = (array: number[], n: number): number => { | ||
| array.sort((a, b) => { | ||
| if (Math.abs(n - a) - Math.abs(n - b) === 0) return a - b; | ||
| return Math.abs(n - a) - Math.abs(n - b); | ||
| }); | ||
| return array[0]; | ||
| }; | ||
|
|
||
| console.log(가까운수([3, 10, 28], 20)); // 28 | ||
| console.log(가까운수([10, 11, 12], 13)); // 12 | ||
|
|
||
| console.log(가까운수2([3, 10, 28], 20)); // 28 | ||
| console.log(가까운수2([10, 11, 12], 13)); // 12 | ||
|
|
||
| console.log(가까운수3([3, 10, 28], 20)); // 28 | ||
| console.log(가까운수3([10, 11, 12], 13)); // 12 |
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 @@ | ||
| // https://school.programmers.co.kr/learn/courses/30/lessons/120835 | ||
|
|
||
| const 진료순서정하기 = (emergency: number[]): number[] => { | ||
| const sortedEM = [...emergency].sort((a, b) => b - a); | ||
| return emergency.map((v) => sortedEM.indexOf(v) + 1); | ||
| }; | ||
|
|
||
| console.log(진료순서정하기([3, 76, 24])); // [3, 1, 2] | ||
| console.log(진료순서정하기([1, 2, 3, 4, 5, 6, 7])); // [7, 6, 5, 4, 3, 2, 1] | ||
| console.log(진료순서정하기([30, 10, 23, 6, 100])); // [2, 4, 3, 5, 1] |
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,24 @@ | ||
| // https://school.programmers.co.kr/learn/courses/30/lessons/120896 | ||
|
|
||
| // ver 1. 최초 코드 | ||
| // 비효율이 보인다. | ||
| const 한번만등장한문자 = (s: string): string => { | ||
| const strMap = new Map(); | ||
| [...s].forEach((v) => { | ||
| const val = strMap.get(v); | ||
| if (!val) strMap.set(v, 1); | ||
| else strMap.set(v, val + 1); | ||
| }); | ||
| return Array.from(strMap) | ||
| .filter((v) => v[1] === 1) | ||
| .join('') | ||
| .match(/[a-z]+/gi) | ||
| ?.sort((a, b) => a.localeCompare(b)) | ||
| .join('') as string; | ||
| }; | ||
|
|
||
| // ver 2. 효율 개선 | ||
|
|
||
| console.log(한번만등장한문자('abcabcadc')); // "d" | ||
| console.log(한번만등장한문자('abdc')); // "abcd" | ||
| console.log(한번만등장한문자('hello')); // "eho" | ||
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.
효율 개선 코드 고민하기