Hi😀! This is my first post in the community🖐. While talking the JavaScript course from freeCodeCamp.org🔥, this simple question struct my if I can calculate the number of alphabet in a string.
I have used Regular Expression to analyze the string. Also used Recursive🔥🔥🔥 function to check I the same alphabet occurs multiple times.
👉👉Here's the code:
const noa=(string)=> {
let quoteSample = !(string==null ||string==undefined)?string.toLowerCase():"";
let alphabetRegex = /[a-z]/gi;
let result = quoteSample.match(alphabetRegex);
if(result==null||result==undefined){
console.log("number of Alphabate is 0")
return 0
}
result= result.sort();
function diet(){
for(let i=0; i<result.length;i++){
if(result[i]==result[i+1]){
result.splice(i,1)
diet();
}
}
}
diet();
return result.length;
}
`
Please let me know your thoughts on How I can optimize this.🙏🙏🙏
Top comments (0)