हमें एक जावास्क्रिप्ट फ़ंक्शन लिखना है जो एक स्ट्रिंग लेता है और एक नया स्ट्रिंग देता है जिसमें सभी गैर-डुप्लिकेट वर्ण हटा दिए जाते हैं।
उदाहरण के लिए -
यदि इनपुट स्ट्रिंग है -
"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