हमें एक JavaScript फ़ंक्शन लिखना है जो एक स्ट्रिंग लेता है और एक नई स्ट्रिंग लौटाता है जिसमें प्रत्येक शब्द का अंतिम स्वर (vowel) हटा दिया गया हो।
उदाहरण
यदि स्ट्रिंग है:
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