কম্পিউটার

জাভাস্ক্রিপ্টে একটি বাক্যে একটি নির্দিষ্ট অক্ষর কতবার প্রদর্শিত হচ্ছে তা খুঁজে বের করা


আমাদের একটি জাভাস্ক্রিপ্ট ফাংশন লিখতে হবে যা বাক্যে একটি নির্দিষ্ট অক্ষর কতবার উপস্থিত হচ্ছে তা খুঁজে বের করে৷

উদাহরণ

এর জন্য কোড হবে −

const string = 'This is just an example string for the program';
const countAppearances = (str, char) => {
   let count = 0;
   for(let i = 0; i < str.length; i++){
      if(str[i] !== char){
         // using continue to move to next iteration
         continue;
      };
      // if we reached here it means that str[i] and char are same
      // so we increase the count
      count++;
   };
   return count;
};
console.log(countAppearances(string, 'a'));
console.log(countAppearances(string, 'e'));
console.log(countAppearances(string, 's'));

আউটপুট

কনসোলে আউটপুট -

3
3
4

  1. জাভাস্ক্রিপ্টে আমরা কতবার সংখ্যা সংখ্যা যোগ করতে পারি

  2. জাভাস্ক্রিপ্টে একটি স্ট্রিং-এ একটি নির্দিষ্ট স্ট্রিংয়ের উপস্থিতি কীভাবে গণনা করা যায়

  3. জাভাস্ক্রিপ্টে নির্দিষ্ট অক্ষর দিয়ে শুরু হওয়া শব্দ খোঁজা

  4. জাভাস্ক্রিপ্ট ব্যবহার করে নির্দিষ্ট সংখ্যক বার স্ট্রিং পুনরাবৃত্তি করা