Problem Solution/Programmers

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] ๋Œ€๋ฌธ์ž์™€ ์†Œ๋ฌธ์ž

yuri lee 2023. 9. 12. 20:56
๋ฐ˜์‘ํ˜•

Problem Description

๋ฌธ์ž์—ด my_string์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, ๋Œ€๋ฌธ์ž๋Š” ์†Œ๋ฌธ์ž๋กœ ์†Œ๋ฌธ์ž๋Š” ๋Œ€๋ฌธ์ž๋กœ ๋ณ€ํ™˜ํ•œ ๋ฌธ์ž์—ด์„ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”.

 

Restrictions

  • 1 ≤ my_string์˜ ๊ธธ์ด ≤ 1,000
  • my_string์€ ์˜์–ด ๋Œ€๋ฌธ์ž์™€ ์†Œ๋ฌธ์ž๋กœ๋งŒ ๊ตฌ์„ฑ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

 

Input/Output Example

  • ์ž…์ถœ๋ ฅ ์˜ˆ # 1 ์†Œ๋ฌธ์ž๋Š” ๋Œ€๋ฌธ์ž๋กœ ๋Œ€๋ฌธ์ž๋Š” ์†Œ๋ฌธ์ž๋กœ ๋ฐ”๊พผ "CCCccc"๋ฅผ returnํ•ฉ๋‹ˆ๋‹ค.
  • ์ž…์ถœ๋ ฅ ์˜ˆ #2 ์†Œ๋ฌธ์ž๋Š” ๋Œ€๋ฌธ์ž๋กœ ๋Œ€๋ฌธ์ž๋Š” ์†Œ๋ฌธ์ž๋กœ ๋ฐ”๊พผ "ABcDeFGHij"๋ฅผ returnํ•ฉ๋‹ˆ๋‹ค.

 

My solution

function solution(my_string) {
    return my_string.split("").map((x) => x == x.toUpperCase() ? x.toLowerCase() : x.toUpperCase()).join("")
}

 


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

 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.

programmers.co.kr

https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase

 

String.prototype.toUpperCase() - JavaScript | MDN

toUpperCase() ๋ฉ”์„œ๋“œ๋Š” ๋ฌธ์ž์—ด์„ ๋Œ€๋ฌธ์ž๋กœ ๋ณ€ํ™˜ํ•ด ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

developer.mozilla.org

 

๋ฐ˜์‘ํ˜•