let's get IT with DAVINA ๐Ÿ’ป

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค]Lv2. JadenCase ๋ฌธ์ž์—ด ๋งŒ๋“ค๊ธฐ ๋ณธ๋ฌธ

DEV_IN/๋ฌธ์ œํ’€์ด

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค]Lv2. JadenCase ๋ฌธ์ž์—ด ๋งŒ๋“ค๊ธฐ

๋‹ค๋นˆ์น˜์ฝ”๋“œ๐Ÿ’Ž 2023. 3. 20. 16:24

โ“ ๋ฌธ์ œ ์„ค๋ช…

JadenCase๋ž€ ๋ชจ๋“  ๋‹จ์–ด์˜ ์ฒซ ๋ฌธ์ž๊ฐ€ ๋Œ€๋ฌธ์ž์ด๊ณ , ๊ทธ ์™ธ์˜ ์•ŒํŒŒ๋ฒณ์€ ์†Œ๋ฌธ์ž์ธ ๋ฌธ์ž์—ด์ž…๋‹ˆ๋‹ค. ๋‹จ, ์ฒซ ๋ฌธ์ž๊ฐ€ ์•ŒํŒŒ๋ฒณ์ด ์•„๋‹ ๋•Œ์—๋Š” ์ด์–ด์ง€๋Š” ์•ŒํŒŒ๋ฒณ์€ ์†Œ๋ฌธ์ž๋กœ ์“ฐ๋ฉด ๋ฉ๋‹ˆ๋‹ค. (์ฒซ ๋ฒˆ์งธ ์ž…์ถœ๋ ฅ ์˜ˆ ์ฐธ๊ณ )
๋ฌธ์ž์—ด s๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, s๋ฅผ JadenCase๋กœ ๋ฐ”๊พผ ๋ฌธ์ž์—ด์„ ๋ฆฌํ„ดํ•˜๋Š” ํ•จ์ˆ˜, solution์„ ์™„์„ฑํ•ด์ฃผ์„ธ์š”.

๐Ÿšซ ์ œํ•œ ์กฐ๊ฑด

  • s๋Š” ๊ธธ์ด 1 ์ด์ƒ 200 ์ดํ•˜์ธ ๋ฌธ์ž์—ด์ž…๋‹ˆ๋‹ค.
  • s๋Š” ์•ŒํŒŒ๋ฒณ๊ณผ ์ˆซ์ž, ๊ณต๋ฐฑ๋ฌธ์ž(" ")๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค.
    • ์ˆซ์ž๋Š” ๋‹จ์–ด์˜ ์ฒซ ๋ฌธ์ž๋กœ๋งŒ ๋‚˜์˜ต๋‹ˆ๋‹ค.
    • ์ˆซ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ง„ ๋‹จ์–ด๋Š” ์—†์Šต๋‹ˆ๋‹ค.
    • ๊ณต๋ฐฑ๋ฌธ์ž๊ฐ€ ์—ฐ์†ํ•ด์„œ ๋‚˜์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.์ž…์ถœ๋ ฅ ์˜ˆ

๐Ÿ—๏ธ ์ž…์ถœ๋ ฅ ์˜ˆ

s return
"3people unFollowed me" "3people Unfollowed Me"
"for the last week" "For The Last Week"

โ—๏ธ๋น„๋‹ˆ's ํ’€์ด

๋ฐ˜๋ณต๋ฌธ์œผ๋กœ arr๋ฅผ ๋Œ๋ ค ์ƒˆ๋กœ์šด ๋ฐฐ์—ด์— pushํ•˜๋Š” ๋ฐฉ๋ฒ•๊นŒ์ง„ ์ƒ๊ฐํ–ˆ์œผ๋‚˜, push(arr[0][0].toUpperCase()), push(arr[0].slice(1)) ์ด๋ ‡๊ฒŒ ๋”ฐ๋กœ ํ•˜๋‹ˆ๊นŒ F or T he L ast W eek๋กœ ๋”ฐ๋กœ ๋ฐฐ์—ด์— ๋“ค์–ด๊ฐ€์„œ ๊ณ„์† ํ…Œ์ŠคํŠธ์ผ€์ด์Šค๋„ ํ†ต๊ณผ๋ฅผ ๋ชปํ–ˆ๋‹ค..

newArr.push(answer[i].charAt(0).toUpperCase() + answer[i].slice(1));

์ฒ˜๋Ÿผ pushํ• ๋•Œ +๋กœ ํ•œ๊บผ๋ฒˆ์— ํ•  ์ˆ˜ ์žˆ์—ˆ๋Š”๋ฐ.. ๋ฉ์ฒญํ–ˆ๋‹ค..

 

๋˜ํ•œ, arr.map์„ ๋Œ๋ฆฌ๊ณ  ๋‹ค์‹œ return arr.join(" ")๋ฅผ ๋”ฐ๋กœ ํ•˜๋ฉด ์›๋ณธ๋ฐฐ์—ด์ด ๋ฐ”๋€Œ์ง€ ์•Š์•„ ๊ณ„์† ๋˜‘๊ฐ™์ด for the last week๋งŒ return๋˜์—ˆ๋‹ค..

์•„๋ž˜์™€ ๊ฐ™์ด map์„ ๋Œ๋ฆฌ๊ณ  ๊ฑฐ๊ธฐ์„œ ๋ฐ”๋กœ join์„ ํ•ด์„œ return์„ ํ•ด์ค˜์•ผ ์›ํ•˜๋Š” ์ •๋‹ต์ด ๋‚˜์˜จ๋Œœ..

function solution(s) {
    let newS=s.toLowerCase();
    let arr=newS.split(" ") //["for", "the", "last", "week"]
    return arr.map((el)=>el.charAt(0).toUpperCase() + el.slice(1)).join(" ")
}
Comments