๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm/์ธํ”„๋Ÿฐ(inflearn)

[ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ(JavaScript) ] 25 - ์œ ํšจํ•œ ํŒฐ๋ฆฐ๋“œ๋กฌ

by YWTechIT 2021. 8. 17.
728x90

๐Ÿ“ 25 - ์œ ํšจํ•œ ํŒฐ๋ฆฐ๋“œ๋กฌ

์ฃผ์–ด์ง„ ๋ฌธ์ž์—ด์ด ํšŒ๋ฌธ์ธ์ง€ ํŒ๋ณ„ํ•˜๋Š” ๋ฌธ์ œ์ธ๋ฐ, ์ถ”๊ฐ€๋กœ ์•ŒํŒŒ๋ฒณ์ด์™ธ์˜ ๋ฌธ์ž๋“ค์€ ๋ฌด์‹œํ•œ๋‹ค. ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์ด์ „์— ํŒŒ์ด์ฌ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ธํ„ฐ๋ทฐ์—์„œ ํ•œ๋ฒˆ ํ’€์–ด๋ณธ์ ์ด ์žˆ๋‹ค. ์•ŒํŒŒ๋ฒณ์ด์™ธ์˜ ๊ฐ’์„ ์ œ๊ฑฐํ•˜๋Š” ๋ฐฉ๋ฒ•์œผ๋กœ ์ •๊ทœํ‘œํ˜„์‹(Reg)์„ ์ด์šฉํ–ˆ๋‹ค.

let s = "found7, time: study; Yduts; emit, 7Dnuof";
console.log(solution(s));

function solution(s){
    s = s.toLowerCase();
    let notIncludeSpecialCharacter = s.replace(/[^a-z]/g, '');
    let compareStr = notIncludeSpecialCharacter.split('').reverse().join('');

    if (notIncludeSpecialCharacter === compareStr) return true;
    return false;
}
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€