-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path033.js
70 lines (63 loc) · 1.05 KB
/
033.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
61
62
63
64
65
66
67
68
69
70
/**
Diberikan sebuah function countMe yang menerima sebuah parameter array of string.
Function ini akan me-return object literal dimana isi dari object tersebut berisi
jumlah karakter pada array of string
Contoh:
input: [ 'dimitri', 'awtian', 'icha' ]
output:
{
d: 1,
i: 5,
m: 1,
t: 2,
r: 1,
a: 3,
w: 1,
n: 1,
c: 1,
h: 1
}
**/
function countMe(names) {
var gabung = names.join('')
var result = {}
for (var i in gabung){
var count = 1;
for (var j in gabung){
if (i !== j){
if (gabung[i] === gabung[j]){
count ++
}
}
}
result[gabung[i]] = count
}
return result
}
console.log(countMe([ 'dimitri', 'awtian', 'icha' ]));
//{
// d: 1,
// i: 5,
// m: 1,
// t: 2,
// r: 1,
// a: 3,
// w: 1,
// n: 1,
// c: 1,
// h: 1
// }
console.log(countMe([ 'dimas', 'ryan', 'akbar', 'tama']));
// {
// d: 1,
// i: 1.
// m: 2,
// a: 6,
// s: 1,
// r: 2,
// y: 1,
// n: 1,
// k: 1,
// b: 1,
// t: 1
// }