-
Notifications
You must be signed in to change notification settings - Fork 0
/
统计字符个数.html
34 lines (30 loc) · 875 Bytes
/
统计字符个数.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script>
var str = 'asdfasdf23fffff42f34dda55433adcsdff';
var str_arr = str.split(''), obj = {};
str_arr.forEach((item) => {
obj[item] ? obj[item]++ : (obj[item] = 1)
})
console.log(obj)
var str = 'asdfasdf23fffff42f34dda55433adcsdff';
var obj2 = str.split('').reduce((r, v) => {
if(r[0].has(v)){
r[1][v] ++;
}else {
r[1][v] = 1;
r[0].add(v);
}
return r;
}, [new Set, {}])[1]
console.log(obj2)
</script>
</body>
</html>