আমাদের একটি জাভাস্ক্রিপ্ট ফাংশন লিখতে হবে যা বড় হাতের এবং ছোট হাতের অক্ষর সহ একটি স্ট্রিং নেয়। ফাংশনটি স্ট্রিংয়ের সামনে সরানো সমস্ত বড় হাতের অক্ষর সহ একটি স্ট্রিং ফেরত দেবে৷
উদাহরণস্বরূপ:যদি ইনপুট স্ট্রিং −
হয়const str = 'heLLO woRlD';
তারপর আউটপুট −
হওয়া উচিতconst output = 'LLORDhe wol';
উদাহরণ
নিম্নলিখিত কোড -
const str = 'heLLO woRlD';
const moveCapitalToFront = (str = '') => {
let capitalIndex = 0;
const newStrArr = [];
for(let i = 0; i < str.length; i++){
if(str[i] !== str[i].toLowerCase()){
newStrArr.splice(capitalIndex, 0, str[i]);
capitalIndex++;
}else{
newStrArr.push(str[i]);
};
};
return newStrArr.join('');
};
console.log(moveCapitalToFront(str)); আউটপুট
নিম্নোক্ত কনসোলে আউটপুট −
LLORDhe wol