সমস্যা
আমাদের একটি জাভাস্ক্রিপ্ট ফাংশন convertToLower() লিখতে হবে যা একটি স্ট্রিং পদ্ধতিতে নেয় যা স্ট্রিংটিকে ছোট হাতের স্ট্রিং-এ রূপান্তর করে এবং নতুন স্ট্রিং প্রদান করে।
উদাহরণস্বরূপ, যদি ফাংশনে ইনপুট হয়
ইনপুট
const str = 'ABcD123';
আউটপুট
const output = 'abcd123';
উদাহরণ
নিম্নলিখিত কোড -
const str = 'ABcD123';
String.prototype.convertToLower = function(){
let res = '';
for(let i = 0; i < this.length; i++){
const el = this[i];
const code = el.charCodeAt(0);
if(code >= 65 && code <= 90){
res += String.fromCharCode(code + 32);
}else{
res += el;
};
};
return res;
};
console.log(str.convertToLower()); আউটপুট
abcd123