समस्या
हमें एक जावास्क्रिप्ट फ़ंक्शन लिखना है जो एक लोअरकेस वर्णमाला स्ट्रिंग लेता है। वर्णमाला में 'a' का सूचकांक 1 है, 'b' का 2, 'c' का 3 ... 'z' का 26। हमारा फ़ंक्शन स्ट्रिंग के सभी अक्षरों के सूचकांक का योग करके परिणाम लौटाएगा।
उदाहरण
निम्न कोड देखें:
const str = 'lowercasestring'; const findScore = (str = '') => { const alpha = 'abcdefghijklmnopqrstuvwxyz'; let score = 0; for(let i = 0; i < str.length; i++){ const el = str[i]; const index = alpha.indexOf(el); score += (index + 1); }; return score; }; console.log(findScore(str));आउटपुट
निम्न कंसोल आउटपुट है:
188