
ch가 word에 포함되지 않았다면 작업을 수행하지 않고 word 반환word 순회ch 탐색ch와 동일한 문자의 인덱스 까지 splicefunction reversePrefix(word: string, ch: string): string {
if(!word.includes(ch)) return word
const splitted = [...word]
for(let i = 0; i < splitted.length; i++) {
if(splitted[i] !== ch) continue
const segment = splitted.splice(0, i + 1)
const reversed = segment.toReversed()
return [...reversed, ...splitted].join('')
}
return word
};