• + 0 comments

    js solution

    javascript
    function designerPdfViewer(h, word) {
      // Write your code here
    
      // data setup for character(s) and height(s)
      const letters = [];
      for (let index = 97; index < 123; index++) {
        letters.push({
          char: String.fromCharCode(index),
          height: h[index - 97],
        });
      }
      // find height
      let heightArray = [];
      for (let index = 0; index < word.length; index++) {
        const element = word.toLowerCase()[index]; // index 0 = a , 1 = b, 2 = c
        const findHeight = letters.find((letter) => letter.char === element);
        heightArray.push(findHeight.height);
      }
    
      // calculate
      const maxHeight = heightArray.sort((a, b) => b - a)[0];
      return maxHeight * word.length;
    }