हमें एक जावास्क्रिप्ट फ़ंक्शन लिखने की आवश्यकता है जो एक लोअरकेस स्ट्रिंग लेता है और एक नई स्ट्रिंग देता है जिसमें [ए, एम] के बीच के सभी तत्वों को 0 द्वारा दर्शाया जाता है और [एन, जेड] के बीच के सभी तत्वों को 1 द्वारा दर्शाया जाता है।पी>
उदाहरण
निम्नलिखित कोड है -
const str = 'Hello worlld how are you';
const stringToBinary = (str = '') => {
const s = str.toLowerCase();
let res = '';
for(let i = 0; i < s.length; i++){
// for special characters
if(s[i].toLowerCase() === s[i].toUpperCase()){
res += s[i];
continue;
};
if(s[i] > 'm'){
res += 1;
}else{
res += 0;
};
};
return res;
};
console.log(stringToBinary(str)); आउटपुट
कंसोल में आउटपुट निम्नलिखित है -
00001 111000 011 010 111