Skip to content

Commit f204843

Browse files
authored
Update 编写一个输出数组中出现次数最多的元素.js
findeMore使用于各种字符串、数组判断出现次数最多的元素或者字符
1 parent ae107a1 commit f204843

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

编写一个输出数组中出现次数最多的元素.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,13 @@ function findMost(arr) {
2222
}
2323
return maxEle
2424
}
25+
26+
const findMost = (arr) => {
27+
let res = arr.toString().split('').sort().join("").match(/(\w)\1+/g);
28+
res.sort(function(a,b) {
29+
return a.length - b.length;
30+
})
31+
console.log('res is : ' + res[res.length-1])
32+
}
33+
2534
findMost([1, 2, 3, 1, 2, 5, 6, 6, 7, 4, 3, 2, 1, 4, 8, 1, 5])

0 commit comments

Comments
 (0)