সমস্যা
এক স্ট্রিং str দেওয়া আছে যাতে তিন ধরনের ক্যারেক্টার থাকতে পারে: ইংরেজি অক্ষর (A-Z, a-z), সংখ্যা (0-9), এবং স্পেশাল ক্যারেক্টার (বাকি সব)। ফাংশনটি স্ট্রিং-এর মাধ্যমে ইটারেট করে একটি অ্যারে তৈরি করবে যাতে ঠিক তিনটি এলিমেন্ট থাকবে: প্রথমে সব অক্ষর, দ্বিতীয়ে সব সংখ্যা, তৃতীয়ে সব স্পেশাল ক্যারেক্টার—রিলেটিভ অর্ডার বজায় রেখে।
উদাহরণ:
ইনপুট
const str = 'thi!1s is S@me23';
আউটপুট
const output = [ 'thisisSme', '123', '! @' ];
উদাহরণ কোড
const str = 'thi!1s is S@me23'; const regroupString = (str = '') => { const res = ['', '', '']; const alpha = 'abcdefghijklmnopqrstuvwxyz'; const numerals = '0123456789'; for(let i = 0; i < str.length; i++){ const el = str[i]; if(alpha.includes(el) || alpha.includes(el.toLowerCase())){ res[0] += el; continue; }; if(numerals.includes(el)){ res[1] += el; continue; }; res[2] += el; }; return res; }; console.log(regroupString(str));আউটপুট
[ 'thisisSme', '123', '! @' ]