DEV Community

Discussion on: JavaScript Code Daily Challenge #5

Collapse
 
nahlagalal profile image
NahlaGalal

We can get index of character by using charCodeAt()

function designerPdfViewer(h, word) {
    let max = 0;
    for(let i in word) {
        const charIndex = word.charCodeAt(i) - 97;
        if(h[charIndex] > max) max = h[charIndex];
    }
    return max * word.length;

}
Enter fullscreen mode Exit fullscreen mode