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

ফর লুপ, ব্রেক এবং কন্টিনিউ ব্যবহার করে সেন্টেন্সে নির্দিষ্ট অক্ষর কতবার আসেছে গণনা করুন - জাভাস্ক্রিপ্ট


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

উদাহরণ

ফাংশনটির কোড নিচে দেওয়া হল −

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. জাভাস্ক্রিপ্টে for loop ফ্লো চার্ট দিয়ে দেখানো

  2. জাভাস্ক্রিপ্টে স্ক্রোল ডাউন লুপ কীভাবে বন্ধ করবেন?

  3. জাভাস্ক্রিপ্টে স্ট্রিংয়ে সর্বোচ্চ কমsekutিভ রিপিটিশন বালা ক্যারেক্টার খুঁজে বের করা

  4. C#-এ break এবং continue স্টেটমেন্ট দিয়ে for লুপ কন্ট্রোল করা