কম্পিউটার টিউটোরিয়াল

জাভাস্ক্রিপ্টে স্ট্রিংয়ের প্রতিটি শব্দ থেকে শেষ স্বরবর্ণ মুছে ফেলা


একটি জাভাস্ক্রিপ্ট ফাংশন লিখতে হবে যা একটি স্ট্রিং গ্রহণ করবে এবং প্রতিটি শব্দ থেকে শেষ স্বরবর্ণটি সরিয়ে একটি নতুন স্ট্রিং ফেরত দেবে।

উদাহরণস্বরূপ, যদি স্ট্রিংটি হয় −

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

  1. জাভাস্ক্রিপ্টে স্ট্রিংয়ের সবচেয়ে লম্বা শব্দ বের করা

  2. জাভাস্ক্রিপ্টে ক্যামেলকেস স্ট্রিং আনক্যামেলাইজ করা

  3. জাভাস্ক্রিপ্টে স্ট্রিং থেকে শুধু কনসোন্যান্ট রিভার্স করা

  4. জাভাস্ক্রিপ্টে স্ট্রিং থেকে নির্দিষ্ট দৈর্ঘ্যের চেয়ে বড় শব্দগুলো বের করা