
sentence를 공백을 기준으로 각 문자 분리dictionary를 길이 기준 오름차 순 정렬function replaceWords(dictionary: string[], sentence: string): string {
const words = sentence.split(" ")
const sortedDicts = dictionary.toSorted((a, b) => a.length - b.length)
const replaced = words.map(word => {
for(const dict of sortedDicts) {
if(word.startsWith(dict)) return dict
}
return word
})
return replaced.join(' ')
};