当前位置:网站首页>Case: count the most characters and times
Case: count the most characters and times
2022-06-25 19:42:00 【Guguwai】
<script>
// Take out each character and add it to o As attribute , Then judge whether the attribute exists , There is an assignment of 1, Again +1;
var str = 'abcoefoxyozzopp';
var o = {};
for (i = 0; i < str.length; i++) {
var chars = str.charAt(i);
if (o[chars]) {//chars Is every character of the string
o[chars]++;
} else {
o[chars] = 1;// Assign a value to a property
}
}
console.log(o);
// Traversing objects
var max = 0;
var ch = '';
for (var k in o) {
//k What you get is the attribute name
// o[k] What you get is the attribute value
if (o[k] > max) {
max = o[k];
ch = k;
}
}
console.log(max);
console.log(' The most common characters are ' + ch);
</script>边栏推荐
- Tcp/ip test questions (III)
- 广州华锐互动VR全景为各行各业带来发展
- System optimization method
- Does GoogleSEO need to change the friend chain? (e6zzseo)
- Mail monitoring cloud script execution progress
- 想知道新股民怎样炒股票开户?在线开户安全么?
- Network security detection and prevention test questions (II)
- Alicloud centos8.0 installing mysql8
- Web components - Basics
- Vscode debugging PHP configuration Xdebug
猜你喜欢

Vulnhub range the planes:earth

削足适履 - 谈谈赛道上的坡道改造

Vulnhub range the planes: mercury

Ali visual AI training camp -day03- construction of electronic photo album (face and expression recognition)

Connecting PHP to MySQL instances in the lamp environment of alicloud's liunx system

Vulnhub range - the planes:venus

Mail monitoring cloud script execution progress

wooyun-2014-065513

ECS 7-day practical training camp (Advanced route) -- day04 -- build a portal using ECs and polardb

【历史上的今天】6 月 25 日:笔记本之父诞生;Windows 98 发布;通用产品代码首次商用
随机推荐
Vscode debugging PHP configuration Xdebug
5、 Initialization analysis II of hikaricp source code analysis
六、HikariConfig的配置解析
Install spoole
MySQL transaction explanation
【C语言练习——打印上三角及其变形(带空格版)】
shell-跳出循环-shift参数左移-函数的使用
Jump jump games auxiliary (manual version) py code implementation
Guangzhou Sinovel interactive creates VR Exhibition Hall panoramic online virtual exhibition hall
Verification code native JS canvas
[today in history] June 25: the father of notebook was born; Windows 98 release; First commercial use of generic product code
Idea common plug-ins
2020-12-09 laravel . Env file loading mechanism process
QQ robot epidemic situation query / epidemic situation concern [latest beta2 version]
削足适履 - 谈谈赛道上的坡道改造
JS mobile phone and computer open different websites
Solidity date tool
Vulnhub range - the planes:venus
Miner's Diary: why should I go mining on April 5, 2021
Error record: preg_ match(): Compilation failed: range out of order in character class at offset 13