๐
Capitalize String
Capitalize String์ฌ์ ๋ฌธ์์ด +10pts
Problem
Write a function that capitalizes the first letter of a string.
Examples
Input:
capitalize("hello")Output:
"Hello"Explanation
์ด ๋ฌธ์ ๋ **๋ฌธ์์ด ๋ถ๋ฆฌ**์ **๋์๋ฌธ์ ๋ณํ**์ ๊ฒฐํฉํ์ฌ ์ฒซ ๊ธ์๋ง ๋๋ฌธ์๋ก ๋ง๋๋ ๋ฐฉ๋ฒ์ ํ์ตํฉ๋๋ค. **ํต์ฌ ์ ๋ต: ๋ถ๋ฆฌ ํ ๊ฒฐํฉ** 1. ์ฒซ ๊ธ์: str[0] 2. ๋๋จธ์ง: str.slice(1) 3. ๊ฒฐํฉ: ๋๋ฌธ์ ์ฒซ ๊ธ์ + ๋๋จธ์ง **"hello" ์ฒ๋ฆฌ ๊ณผ์ ** - str[0] โ "h" - "h".toUpperCase() โ "H" - str.slice(1) โ "ello" - "H" + "ello" โ "Hello" **๋น ๋ฌธ์์ด ์ฒ๋ฆฌ** ๋น ๋ฌธ์์ด์์ str[0]์ undefined์ ๋๋ค. ์ด ๊ฒฝ์ฐ ์...
View detailed explanation โKey Concepts
toUpperCase ๋ฉ์๋ slice ๋ฉ์๋ ๋ฌธ์์ด ์ธ๋ฑ์ฑ ๋น ๋ฌธ์์ด ์ฒ๋ฆฌ
Time: O(n) Space: O(n)
solution.js
Ctrl + Enter
Run tests to see results here.