count no of punctuation in string in js

Solutions on MaxInterview for count no of punctuation in string in js by the best coders in the world

showing results for - "count no of punctuation in string in js"
Philipp
12 Nov 2019
1function countPunctuation(str) {
2   const punct = "!,\;\.-?";
3   let count = 0;
4   for(let i = 0; i < str.length; i++){
5      if(!punct.includes(str[i])){
6         continue;
7      };
8      count++;
9   };
10   return count;
11}