영어에서 이 모든 문자는 구두점으로 간주됩니다 -
'!', "," ,"\'" ,";" ,"\"", ".", "-" ,"?"
문자열을 받아서 문자열에서 이러한 구두점의 출현 횟수를 계산하고 그 개수를 반환하는 JavaScript 함수를 작성해야 합니다.
예시
이 함수의 코드를 작성해 봅시다 -
const str = "This, is a-sentence;.Is this a sentence?";
const countPunctuation = str => {
const punct = "!,\;\.-?";
let count = 0;
for(let i = 0; i < str.length; i++){
if(!punct.includes(str[i])){
continue;
};
count++;
};
return count;
};
console.log(countPunctuation(str)); 출력
콘솔의 출력:−
5