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