๐ŸŸฃ ์˜ค๋Š˜์˜ ๋ฌธ์ œ ํšŒ๊ณ 

๊น€ํƒœ์šฑยท2023๋…„ 6์›” 2์ผ
0
post-thumbnail

๐Ÿ˜ญ ๋ฌธ์ œ ํ•ฅ์ง #1

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] Lv0 : ์กฐ๊ฑด ๋ฌธ์ž์—ด

๋ฌธ์ œ ์„ค๋ช…
๋ฌธ์ž์—ด์— ๋”ฐ๋ผ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋‘ ์ˆ˜์˜ ํฌ๊ธฐ๋ฅผ ๋น„๊ตํ•˜๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

๋‘ ์ˆ˜๊ฐ€ n๊ณผ m์ด๋ผ๋ฉด
">", "=" : n >= m
"<", "=" : n <= m
">", "!" : n > m
"<", "!" : n < m
๋‘ ๋ฌธ์ž์—ด ineq์™€ eq๊ฐ€ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. ineq๋Š” "<"์™€ ">"์ค‘ ํ•˜๋‚˜๊ณ , eq๋Š” "="์™€ "!"์ค‘ ํ•˜๋‚˜์ž…๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๋‘ ์ •์ˆ˜ n๊ณผ m์ด ์ฃผ์–ด์งˆ ๋•Œ, n๊ณผ m์ด ineq์™€ eq์˜ ์กฐ๊ฑด์— ๋งž์œผ๋ฉด 1์„ ์•„๋‹ˆ๋ฉด 0์„ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”.

์•”ํ˜ธํ™”๋œ ๋ฌธ์ž์—ด cipher๋ฅผ ์ฃผ๊ณ ๋ฐ›์Šต๋‹ˆ๋‹ค.
๊ทธ ๋ฌธ์ž์—ด์—์„œ code์˜ ๋ฐฐ์ˆ˜ ๋ฒˆ์งธ ๊ธ€์ž๋งŒ ์ง„์งœ ์•”ํ˜ธ์ž…๋‹ˆ๋‹ค.
๋ฌธ์ž์—ด cipher์™€ ์ •์ˆ˜ code๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ ํ•ด๋…๋œ ์•”ํ˜ธ ๋ฌธ์ž์—ด์„ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”.

์ œํ•œ์‚ฌํ•ญ

  • 1 โ‰ค n, m โ‰ค 100

์ž…์ถœ๋ ฅ ์˜ˆ

ineqeqnmresult
"<""="20501
">""!"41780

๋‚˜์˜ ํ’€์ด

function solution(ineq, eq, n, m) {
    let answer = 0
 
 if(ineq == "<" && eq == "=") {
            if(n <= m) answer = 1;
        }
        else if(ineq == "<" && eq == "!") {
            if(n < m) answer = 1;
        }
        else if(ineq == ">" && eq == "=") {
            if(n >= m) answer = 1;
        }
        else if(ineq == ">" && eq == "!") {
            if(n > m) answer = 1;
        }
        else answer = 0;
    
        return answer;
    
}

๋‹ค๋ฅธ ์‚ฌ๋žŒ ํ’€์ด

const operations = {
  '>=': (n, m) => n >= m,
  '<=': (n, m) => n <= m,
  '>!': (n, m) => n > m,
  '<!': (n, m) => n < m,
};

function solution(ineq, eq, n, m) {
  const op = operations[ineq + eq];
  return Number(op(n, m));
}

#ํ’€์ด ์ดํ•ด
1. ๊ฐ์ฒด๋ฅผ ํ†ตํ•ด ๋ฌธ์ž์—ด ์กฐ๊ฑด์„ ์†์„ฑ๊ฐ’์œผ๋กœ ์ง€์ •
arrow ํ•จ์ˆ˜๋ฅผ ์ ์šฉ์‹œ์ผœ ๋ฌธ์ž์—ด์˜ ์กฐ๊ฑด์„ return ํ•˜๋Š” ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค์–ด ๋ƒ„.

profile
๋ฐฉ๋ฒ•์„ ์—ฐ๊ตฌํ•  ์ค„ ์•„๋Š” ๊ฐœ๋ฐœ์ž!

0๊ฐœ์˜ ๋Œ“๊ธ€