हमें एक JavaScript फ़ंक्शन लिखना होगा जो एक स्ट्रिंग लेता है और प्रत्येक शब्द का अंतिम स्वर हटाकर एक नई स्ट्रिंग लौटाता है।
उदाहरण के लिए: यदि स्ट्रिंग है:
const str = 'This is an example string';
तब आउटपुट होना चाहिए:
const output = 'Ths s n exampl strng';
इसलिए, आइए इस फ़ंक्शन के लिए कोड लिखते हैं:
उदाहरण
इसका कोड निम्नलिखित होगा:
const str = 'This is an example string';
const removeLast = word => {
const lastIndex = el => word.lastIndexOf(el);
const ind = Math.max(lastIndex('a'), lastIndex('e'), lastIndex('i'), lastIndex('o'), lastIndex('u'));
return word.substr(0, ind) + word.substr(ind+1, word.length);
}
const removeLastVowel = str => {
const strArr = str.split(' ');
return strArr.reduce((acc, val) => {
return acc.concat(removeLast(val));
}, []).join(' ');
};
console.log(removeLastVowel(str));
आउटपुट
कंसोल में आउटपुट होगा:
Ths s n exampl strng