আমাদের একটি জাভাস্ক্রিপ্ট ফাংশন লিখতে হবে যা একটি স্ট্রিং নেয় এবং প্রতিটি শব্দের শেষ স্বর দিয়ে একটি নতুন স্ট্রিং ফিরিয়ে দেয়।
যেমন − যদি স্ট্রিং হয় −
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