
😎풀이
caption을 공백 기준으로 분리
- 첫 단어 외에는 모두 첫 글자가 대문자, 이외엔 소문자로 변환되므로, 특수문자를 제외한 영문자를 해당 규칙에 맞추어 변환
- 첫 글자는 모두 소문자로 변환
- #{첫단어}{이후 단어} 포멧으로 태그 생성
- 100자 까지만 반환
function generateTag(caption: string): string {
const words = caption.split(' ').filter(Boolean)
const camelCases = words.slice(1).map(word => {
const onlyEng = word.replaceAll(/[^\w]/g, '')
return onlyEng[0].toUpperCase() + onlyEng.slice(1).toLowerCase()
})
const firstWord = (words[0] ?? '').toLowerCase()
const tag = '#' + firstWord + camelCases.join('')
return tag.slice(0, 100)
};