আমাদের একটি জাভাস্ক্রিপ্ট ফাংশন লিখতে হবে যা একটি স্ট্রিং নিবে। ফাংশনটি স্ট্রিংয়ে কতগুলো আলফাবেট (বড় হাতের বা ছোট হাতের) আছে সেটা গণনা করবে।
উদাহরণ - ইনপুট স্ট্রিং:
const str = 'this is a string!';
আউটপুট হবে:
13
উদাহরণ
এটির কোড হবে:
const str = 'this is a string!'; const isAlpha = char => { const legend = 'abcdefghijklmnopqrstuvwxyz'; return legend.includes(char); }; const countAlphabets = (str = '') => { let count = 0; for(let i = 0; i < str.length; i++){ if(!isAlpha(str[i])){ continue; }; count++; }; return count; }; console.log(countAlphabets(str));
আউটপুট
কনসোলে আউটপুট হবে:
13