समस्या
हमें एक JavaScript फ़ंक्शन लिखना है जो एक स्ट्रिंग लेता है और स्ट्रिंग से सभी विशेष कैरेक्टर्स को हटाकर केवल अल्फाबेट्स और न्यूमरल्स को परिणाम स्ट्रिंग में छोड़ देता है।
इनपुट
const str = 'th@is Str!ing Contains 3% punctuations';
आउटपुट
const output = 'thisStringContains3punctuations';
क्योंकि हमने सभी पंक्चुएशन और व्हाइटस्पेस हटा दिए।
उदाहरण
निम्नलिखित कोड है −
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