forked from Morgantheplant/coderbyte
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLetterCountI.js
60 lines (32 loc) · 1014 Bytes
/
LetterCountI.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
function LetterCountI(str) {
var arr = str.split(" ");
var dupCount = [];
for (var k = 0; k < arr.length; k++) {
var stringer = arr[k];
var holder = 0;
for (var i = 0; i < stringer.length; i++ ){
var count = 0;
for (var j = 0; j < stringer.length; j++){
if(stringer[i] == stringer[j]){
count++;
if(count > holder){
holder = count;
}
}
}
}
dupCount.push(holder + stringer);
}
dupCount.sort();
var str = dupCount.pop();
if (str[0] == 1){
str = -1;
} else {
str = str.replace(/\d+/g,"");
}
// code goes here
return str;
}
// keep this function call here
// to see how to enter arguments in JavaScript scroll down
LetterCountI(readline());