हमें एक जावास्क्रिप्ट फ़ंक्शन लिखना है जो एक स्ट्रिंग लेता है और एक नई स्ट्रिंग लौटाता है जिसमें से सभी नॉन-डुप्लिकेट कैरेक्टर्स हटा दिए गए हों।
उदाहरण के लिए -
यदि इनपुट स्ट्रिंग है -
"teeth_foot"
तो आउटपुट होना चाहिए -
"teetoot"
इसलिए, आइए इस फ़ंक्शन के लिए कोड लिखते हैं।
उदाहरण
const str = 'teeth_foot';
const removeNonDuplicate = str => {
const strArray = str.split("");
const duplicateArray = strArray.filter(el => {
return strArray.indexOf(el) !== strArray.lastIndexOf(el);
});
return duplicateArray.join("");
};
console.log(removeNonDuplicate(str));आउटपुट
कंसोल में आउटपुट होगा -
teetoot