সমস্যা
আমাদের একটি জাভাস্ক্রিপ্ট ফাংশন লিখতে হবে যা একটি স্ট্রিং নেবে এবং স্ট্রিং থেকে সকল スペシャル ক্যারেক্টার সরিয়ে শুধু অক্ষর ও সংখ্যা রেখে দেবে।
ইনপুট
const str = 'th@is Str!ing Contains 3% punctuations';আউটপুট
const output = 'thisStringContains3punctuations';কারণ আমরা সকল puntuations এবং whitespace সরিয়ে দিয়েছি।
উদাহরণ
নিচে কোডটি দেওয়া হলো:
const str = 'th@is Str!ing Contains 3% punctuations';
const removeSpecialChars = (str = '') => {
let res = '';
for(let i = 0; i < str.length; i++){
const el = str[i];
if(+el){
res += el;
}else if(el.toLowerCase() !== el.toUpperCase()){
res += el;
}
continue;
}
return res;
};
console.log(removeSpecialChars(str));আউটপুট
thisStringContains3punctuations