हमें एक JavaScript फ़ंक्शन लिखना है जो एक स्ट्रिंग लेता है और उसे मैक्सिकन वेव में बदलता है, यानी प्रत्येक शब्द में क्रमिक कैपिटल अक्षरों वाली स्ट्रिंग बनाता है।
उदाहरण के लिए:
यदि स्ट्रिंग है:
const str = 'edabit';
तो आउटपुट होना चाहिए:
const output = ["Edabit", "eDabit", "edAbit", "edaBit", "edabIt", "edabiT"];
उदाहरण
निम्नलिखित कोड देखें:
const str = 'edabit';
const replaceAt = function(index, char) {
let a = this.split("");
a[index] = char;
return a.join("");
};
String.prototype.replaceAt = replaceAt;
const createEdibet = word => {
let array = word.split('');
const res = array.map((letter, i) => {
let a = word.replaceAt(i, letter.toUpperCase());
return a;
});
return res;
};
console.log(createEdibet(str));
यह कंसोल पर निम्नलिखित आउटपुट देगा:
[ 'Edabit', 'eDabit', 'edAbit', 'edaBit', 'edabIt', 'edabiT' ]