একটি জাভাস্ক্রিপ্ট ফাংশন লিখতে হবে যা দুটি স্ট্রিং নেবে যেগুলো কিছু সাধারণ উপাদান ধারণ করতে পারে / নাও পারে। ফাংশনটি খালি স্ট্রিং রিটার্ন করবে যদি কোনো সাধারণ উপাদান না থাকে, অন্যথায় দুটি স্ট্রিং-এর মধ্যে সব সাধারণ উপাদান ধারণকারী একটি স্ট্রিং রিটার্ন করবে।
আমাদের দুটি স্ট্রিং −
const str1 = 'Hey There!!, how are you'; const str2 = 'Can this be a special string';
উদাহরণ
নিচে কোডটি দেওয়া হল −
const str1 = 'Hey There!!, how are you'; const str2 = 'Can this be a special string'; const commonString = (str1, str2) => { let res = ''; for(let i = 0; i < str1.length; i++){ if(!str2.includes(str1[i])){ continue; }; res += str1[i]; }; return res; }; console.log(commonString(str1, str2));আউটপুট
কনসোলে নিচের আউটপুট দেখা যাবে −
e here h are