๐ค ์์งlog ๐ค
[ํ๋ก๊ทธ๋๋จธ์ค:Javascript] ๋ฌธ์์ด ๋ค์ง๊ธฐ ๋ณธ๋ฌธ
๐ ํ๋ก๊ทธ๋๋จธ์ค
[ํ๋ก๊ทธ๋๋จธ์ค:Javascript] ๋ฌธ์์ด ๋ค์ง๊ธฐ
Eun_zii 2023. 10. 13. 11:17ํ๋ก๊ทธ๋๋จธ์ค Lv.0
- ๋ฌธ์์ด ๋ค์ง๊ธฐ
๐ ๋ฌธ์ ์ค๋ช
- ๋ฌธ์์ด my_string์ด ๋งค๊ฐ๋ณ์๋ก ์ฃผ์ด์ง๋๋ค. my_string์ ๊ฑฐ๊พธ๋ก ๋ค์ง์ ๋ฌธ์์ด์ returnํ๋๋ก solution ํจ์๋ฅผ ์์ฑํด์ฃผ์ธ์.
๐ ์ ํ์กฐ๊ฑด
- 1 ≤ my_string์ ๊ธธ์ด ≤ 1,000
๐ ๋ฌธ์
function solution(my_string) {
var answer = '';
return answer;
}
๐ ํ์ด
function solution(my_string) {
var answer = '';
answer = my_string.split('').reverse().join('');
return answer;
}
split() ๋ฉ์๋๋ก string ๊ฐ์ฒด๋ฅผ ๋ฌธ์์ด๋ก ๋๋ํ reverse() ๋ฉ์๋๋ก ๋ฐฐ์ด์ ์์๋ฅผ ๋ค์ง์ด ์ค๋ค. ๊ทธํ join() ๋ฉ์๋๋ก ์ฐ๊ฒฐํ์ฌ ๋ฌธ์์ด์ ๋ฐํํด์ค๋ค.
โ split()
: split() ๋ฉ์๋๋ String ๊ฐ์ฒด๋ฅผ ์ง์ ํ ๊ตฌ๋ถ์๋ฅผ ์ด์ฉํ์ฌ ์ฌ๋ฌ ๊ฐ์ ๋ฌธ์์ด๋ก ๋๋๋๋ค.
const str = 'The quick brown fox jumps over the lazy dog.';
const words = str.split(' ');
console.log(words[3]);
// Expected output: "fox"
const chars = str.split('');
console.log(chars[8]);
// Expected output: "k"
const strCopy = str.split();
console.log(strCopy);
// Expected output: Array ["The quick brown fox jumps over the lazy dog."]
โ join()
: join() ๋ฉ์๋๋ ๋ฐฐ์ด์ ๋ชจ๋ ์์๋ฅผ ์ฐ๊ฒฐํด ํ๋์ ๋ฌธ์์ด๋ก ๋ง๋ญ๋๋ค.
const elements = ['Fire', 'Air', 'Water'];
console.log(elements.join());
// Expected output: "Fire,Air,Water"
console.log(elements.join(''));
// Expected output: "FireAirWater"
console.log(elements.join('-'));
// Expected output: "Fire-Air-Water"
728x90
'๐ ํ๋ก๊ทธ๋๋จธ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค:Javascript] ์ ์ ์์น ๊ตฌํ๊ธฐ (1) | 2023.10.27 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค:Javascript] ์ค๋ณต๋ ์ซ์ ๊ฐ์ (0) | 2023.10.13 |
[ํ๋ก๊ทธ๋๋จธ์ค:Javascript] ๋ฐฐ์ด๋ค์ง๊ธฐ (0) | 2023.10.13 |
[ํ๋ก๊ทธ๋๋จธ์ค:Javascript] ํธ์ง (0) | 2023.10.13 |
[ํ๋ก๊ทธ๋๋จธ์ค:Javascript] ์์ด์ค ์๋ฉ๋ฆฌ์นด๋ ธ (0) | 2023.01.19 |