๐Ÿค ์€์ง€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