समस्या
हमें एक जावास्क्रिप्ट फ़ंक्शन लिखना है जो अंग्रेजी लोअरकेस वर्णमाला की एक स्ट्रिंग लेता है। हमारा फ़ंक्शन एक नई स्ट्रिंग बनाएगा जिसमें प्रत्येक अक्षर को स्ट्रिंग में उनके 1-आधारित सूचकांक की संख्या में दोहराया जाए, कैपिटल केस में और विभिन्न अक्षर सेट को डैश '-' से अलग किया जाए।
इसलिए, स्ट्रिंग 'abcd' बननी चाहिए:
"A-Bb-Ccc-Dddd"
उदाहरण
निम्न कोड देखें:
const str = 'abcd'; const repeatStrings = (str) => { const res = []; for(let i = 0; i < str.length; i++){ const el = str[i]; let temp = el.repeat(i + 1); temp = temp[0].toUpperCase() + temp.substring(1, temp.length); res.push(temp); }; return res.join('-'); }; console.log(repeatStrings(str));आउटपुट
A-Bb-Ccc-Dddd