-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdesignerPdfViewer.js
35 lines (33 loc) · 1.07 KB
/
designerPdfViewer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
* Complete the 'designerPdfViewer' function below.
*
* The function is expected to return an INTEGER.
* The function accepts following parameters:
* 1. INTEGER_ARRAY h
* 2. STRING word
*/
function designerPdfViewer(h, word) {
// Write your code here
word.toLowerCase();
let wordLength = word.length;
let index=0;
let val=0;
let tempTab = [];
let valMax = 0;
let res = 0;
let alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];
for(let i=0; i<word.length; i++){
index = alphabet.indexOf(word[i]);
val = h[index];
tempTab.push(val);
}
valMax = Math.max(...tempTab);
res = valMax * wordLength;
return res;
}
module.exports = designerPdfViewer;
// let h = [1, 3, 1, 3, 1, 4, 1, 3, 2, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5];
// let word = "abc"; //9
let h = [1, 3, 1, 3, 1, 4, 1, 3, 2, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 7];
let word = "zaba"; //28
console.log(designerPdfViewer(h, word));