Skip to content
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

1-honggukang0623 #5

Merged
merged 3 commits into from
Apr 5, 2024
Merged

1-honggukang0623 #5

merged 3 commits into from
Apr 5, 2024

Conversation

Ghdrn1399
Copy link
Contributor

πŸ”— 문제 링크

https://school.programmers.co.kr/learn/courses/30/lessons/120808

βœ”οΈ μ†Œμš”λœ μ‹œκ°„

30뢄정도 μ†Œμš”

✨ μˆ˜λ„ μ½”λ“œ

λ¬Έμ œμš”μ•½
jsλ₯Ό μ‚¬μš©ν•œ μ—°μ‚° λ¬Έμ œν’€κΈ°(λΆ„μˆ˜μ˜ λ§μ…ˆ)

1.λΆ„λͺ¨λ§μ…ˆ

const numer = numer1 * denom2 + numer2 * denom1;
 const denom = denom1 * denom2;

2.λΆ„μžλΆ„λͺ¨μ˜ μ΅œλŒ€κ³΅μ•½μˆ˜λ‘œ λ‚˜λˆ μ€Œ

2-1.λΆ„μžλΆ„λͺ¨ 쀑 μž‘μ€ 수λ₯Ό μ°ΎκΈ°
λΉ„κ΅μ—°μ‚°μž ifλ¬Έ μ‚¬μš©ν•˜μ—¬ μž‘μ€μˆ˜λ₯Ό μ°ΎκΈ°.

if(numer < denom){
        minNumber = numer;
    } else {
        minNumber = denom;
    }

2-2. μž‘μ€μˆ˜λ₯Ό λΆ„μžλΆ„λͺ¨λ‘œ λ‚˜λˆ λ³΄κΈ°
μœ— λ‹¨κ³„μ—μ„œ μž‘μ€μˆ˜λ₯Ό κ΅¬ν–ˆμœΌλ‹ˆκΉ μž‘μ€μˆ˜λ‘œ λΆ„μž λΆ„λͺ¨λ₯Ό λ‚˜λˆ λ³΄κΈ°.

2-3. λ‘˜λ‹€ λ‚˜λˆ„μ–΄ 떨어지면 κ·Έ λ‚˜λˆˆ μˆ˜κ°€ μ΅œλŒ€κ³΅μ•½μˆ˜
λ‚˜λˆ„μ–΄ λ–¨μ–΄μ§€λŠ” 것 -> λ‚˜λ¨Έμ§€κ°€ 0인것 (%μ—°μ‚°μžλ₯Ό μ‚¬μš©ν•΄λ³΄κΈ°)

if(numer % minNumber === 0){
        if(denom % minNumber === 0)

2-4. μ•ˆ λ‚˜λˆ„μ–΄λ–¨μ–΄μ§€λ©΄ μž‘μ€ 수λ₯Ό 1 쀄이고 2-2둜 λŒμ•„κ°€κΈ°
minNumberλ₯Ό -1 ν•΄μ£Όκ³  반볡문 while문을 μ‚¬μš©ν•΄λ³΄κΈ°.

while(true){ 
    if(numer % minNumber === 0){
        if(denom % minNumber === 0){
            return [numer / minNumber, denom / minNumber];
        }
    }
    minNumber = minNumber -1;
   }
}

μ΅œμ’…μ½”λ“œ

function solution(numer1, denom1, numer2, denom2) {
    var answer = [];
    const numer = numer1 * denom2 + numer2 * denom1;
    const denom = denom1 * denom2;
    
    let minNumber;
    if(numer < denom){
        minNumber = numer;
    } else {
        minNumber = denom;
    }
    
    
   while(true){ 
    if(numer % minNumber === 0){
        if(denom % minNumber === 0){
            return [numer / minNumber, denom / minNumber];
        }
    }
    minNumber = minNumber -1;
   }
}

πŸ“š μƒˆλ‘­κ²Œ μ•Œκ²Œλœ λ‚΄μš©

ν‰μ†Œ Cμ–Έμ–΄, 파이썬 λ“± λ‹€μ–‘ν•œ μ–Έμ–΄μ½”λ“œλ₯Ό μ ‘ν•΄λ΄€μ§€λ§Œ 이번 μ•Œκ³ λ¦¬λ“œλ―Έλ₯Ό 톡해 μžλ°” 슀크립트둜 κ°„λ‹¨ν•œ 문제λ₯Ό ν’€μ–΄λ³΄λ©΄μ„œ μƒˆλ‘œμš΄ 언어에도 μ΅μˆ™ν•΄μ§€κ²Œ λ˜λŠ” κ³„κΈ°μ˜€μŠ΅λ‹ˆλ‹€.

@alstjr7437
Copy link
Member

@honggukang0623
였호 JS둜 ν•˜μ‹œλŠ”λΆ„μ€ μ˜€λž˜λ§Œμ— λ³΄λ‚΄μš”!!

ν˜Ήμ‹œ λ”°λ‘œ JS둜 ν•˜μ‹œκ²Œ 된 계기가 μžˆμœΌμ‹€κΉŒμš”?

@Ghdrn1399
Copy link
Contributor Author

Ghdrn1399 commented Mar 28, 2024

@honggukang0623 였호 JS둜 ν•˜μ‹œλŠ”λΆ„μ€ μ˜€λž˜λ§Œμ— λ³΄λ‚΄μš”!!

ν˜Ήμ‹œ λ”°λ‘œ JS둜 ν•˜μ‹œκ²Œ 된 계기가 μžˆμœΌμ‹€κΉŒμš”?

μš°μ„  이번이 μ•Œκ³ λ¦¬λ“œλ―Έ 첫 ν™œλ™μ΄λΌμ„œ ν‰μ†Œμ— 많이 μ ‘ν•  수 μžˆλŠ” Cλ‚˜ Python, μžλ°” μ–Έμ–΄ 말고 μƒˆλ‘œμš΄ μ–Έμ–΄λ₯Ό μ‚¬μš© ν•΄ λ³΄κ³ μ‹Άμ—ˆκ³  ν‰μ†Œμ—λ„ js언어에 관심이 μžˆμ—ˆμ–΄μ„œ μ΄λ²ˆκΈ°νšŒμ— μ‹€λ ₯을 μ¦μ§„μ‹œν‚€κ³  μ‹Άμ—ˆμŠ΅λ‹ˆλ‹€ ^^

Copy link
Member

@oesnuj oesnuj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR 잘 μ½μ—ˆμŠ΅λ‹ˆλ‹€! μžλ°”μŠ€ν¬λ¦½νŠΈ 곡뢀쀑인데 μ—¬κΈ°μ„œ μ ‘ν•˜κ²Œλ˜μ–΄ λ°˜κ°‘λ„€μš”
μ΅œλŒ€ κ³΅μ•½μˆ˜λ₯Ό κ΅¬ν•˜κΈ°μœ„ν•΄ -1μ”© ν•˜λŠ” λ‘œμ§μ„ μ‚¬μš©ν•˜μ…¨λŠ”λ°
μ΅œλŒ€ κ³΅μ•½μˆ˜λ₯Ό 더 효율적으둜 μ°Ύμ•„λ‚΄λŠ” μ•Œκ³ λ¦¬μ¦˜ 쀑 ν•˜λ‚˜μΈ μœ ν΄λ¦¬λ“œ ν˜Έμ œλ²•μ„ μ•Œμ•„λ³΄μ‹œλ©΄ 쒋을 것 κ°™μ•„μš”!
이 μ•Œκ³ λ¦¬μ¦˜μ΄ μˆ«μžκ°€ 클 κ²½μš°μ— 더 효율적으둜 μž‘λ™ν•©λ‹ˆλ‹€!

function gcd(a, b) {
    while (b !== 0) {
        let temp = b;
        b = a % b;
        a = temp;
    }
    return a;
}

Copy link
Collaborator

@pu2rile pu2rile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

였호 μžλ°”μŠ€ν¬λ¦½νŠΈ μ‚¬μš©ν•˜μ‹œλŠ” 뢄은 μ €λŠ” 거의 처음 λ³΄λŠ” 것 κ°™μ•„μ„œ μ‹ κΈ°ν•΄μš”!
μƒˆλ‘œμš΄ μ–Έμ–΄ ν•™μŠ΅μ„ μœ„ν•΄ μžλ°”μŠ€ν¬λ¦½νŠΈλ₯Ό μ‚¬μš©ν•˜μ…¨λ‹€κ³  ν–ˆλŠ”λ° μ•Œκ³ λ¦¬λ“œλ―Έλ₯Ό 이런 λ°©μ‹μœΌλ‘œ ν™œμš©ν•˜λŠ” 것도 μ œλ²• μ’‹μ•„ λ³΄μ΄λ„€μš§ 저도 μ¨λ¨Ήκ² μŠ΅λ‹ˆλ‹€ γ…Žγ…Ž 첫 pr μˆ˜κ³ ν•˜μ…¨μ–΄μš”~

Copy link
Collaborator

@suhyun113 suhyun113 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jsμ–Έμ–΄λŠ” ν•œ λ²ˆλ„ μ‚¬μš©ν•΄λ³Έ 적이 μ—†μ–΄ μ½”λ“œλ₯Ό 이해할 수 μžˆμ„μ§€ κ±±μ •ν–ˆμŠ΅λ‹ˆλ‹€. 그런데, ν™κ΅¬λ‹˜μ΄ μž‘μ„±ν•˜μ‹  μˆ˜λ„ μ½”λ“œλ₯Ό λ³΄λ‹ˆ μ„€λͺ…이 λ„ˆλ¬΄ μƒμ„Ένžˆ λ˜μ–΄μžˆμ–΄ 이해가 잘 λ˜μ—ˆμŠ΅λ‹ˆλ‹€. 곧 μˆ˜μ—… μ‹œκ°„μ— jsλ₯Ό 배우게 λ˜λŠ”λ°, 미리 μ‚΄νŽ΄λ³΄κ³  κ°€λŠ” 것 κ°™μ•„ 큰 도움이 λ˜μ—ˆμŠ΅λ‹ˆλ‹€.

  • μ½”λ“œλ₯Ό μ΄ν•΄ν•˜λ©΄μ„œ 보던 쀑에 μ™œ μ΅œλŒ€κ³΅μ•½μˆ˜λ₯Ό μ°ΎλŠ”λ°, -1μ”© ν•΄μ•Όν•˜λŠ”μ§€ 의문이 λ“€μ—ˆκ³  더 μ‰¬μš΄ 방법이 μžˆμ„ 것 κ°™λ‹€λŠ” 생각이 λ“€μ—ˆμŠ΅λ‹ˆλ‹€. μ€€μ„œλ‹˜μ˜ 리뷰λ₯Ό λ³΄λ‹ˆ μœ ν΄λ¦¬λ“œ ν˜Έμ œλ²•μ΄λΌλŠ” 것이 μžˆλŠ” λ“― ν•˜μ—¬ 또 μƒˆλ‘œμš΄ κ°œλ…μ„ μ•Œκ²Œλ˜μ–΄ μ’‹μ•˜μŠ΅λ‹ˆλ‹€. μ’€ 더 효율적으둜 μž‘λ™ν•˜λŠ” μ•Œκ³ λ¦¬μ¦˜μΈ 것 κ°™μŠ΅λ‹ˆλ‹€! μ°Έκ³ ν•˜μ‹œλ©΄ 쒋을 λ“― ν•΄μš”.

쒋은 μ½”λ“œ λ³΄μ—¬μ£Όμ…”μ„œ js에 λŒ€ν•΄ κ³΅λΆ€ν•˜κ³  κ°‘λ‹ˆλ‹€~
첫 PR μž‘μ„±ν•΄μ£Όμ‹ λ‹€κ³  μˆ˜κ³ λ§ŽμœΌμ…¨μ–΄μš”!!

@Ghdrn1399 Ghdrn1399 merged commit 3e585b5 into main Apr 5, 2024
@Ghdrn1399 Ghdrn1399 deleted the 1-honggukang0623 branch April 5, 2024 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants