// --- Directions
// Given a string, return the character that is most
// commonly used in the string.
// --- Examples
// maxChar("abcccccccd") === "c"
// maxChar("apple 1231111") === "1" function maxChar(str) {
let m = {},
max = -1,
result = null; for (let char of str) {
m[char] = m[char] + 1 || 1;
} for (let [key, count] of Object.entries(m)) {
max = Math.max(max, count);
if (max === count) {
result = key;
}
} return result;
} module.exports = maxChar;

  

const maxChar = require('./index');

test('maxChar function exists', () => {
expect(typeof maxChar).toEqual('function');
}); test('Finds the most frequently used char', () => {
expect(maxChar('a')).toEqual('a');
expect(maxChar('abcdefghijklmnaaaaa')).toEqual('a');
}); test('Works with numbers in the string', () => {
expect(maxChar('ab1c1d1e1f1g1')).toEqual('1');
});

  

最新文章

  1. 用eclipse开发和调试postgresql-8.4.1
  2. Note_Master-Detail Application(iOS template)_05_ YJYMasterViewController.m
  3. NFC(5)编写NFC程序的基本步骤
  4. Android集成科大讯飞SDK语音听写及语音合成功能实现
  5. 高级UIKit-08(TCPSocket)
  6. keystore 介绍
  7. 进程与进程描写叙述符(task_struct)
  8. 如何在MQ中实现支持任意延迟的消息?
  9. mybatis批量提交
  10. Mac软件安装提示程序已损坏解决方案
  11. Mybatis集成Oracle
  12. Quartz.NET 任务调度教程。
  13. 山寨版 WP8.1 Cortana 启动 PC
  14. Image Restoration[Deep Image Prior]
  15. python中lambda表达式中自由变量的坑,因为for循环结束了 变量还保存着,详见关于for循环的随笔
  16. java BASE64流 输出图片。
  17. 基于Confluent.Kafka实现的KafkaConsumer消费者类和KafkaProducer消息生产者类型
  18. URAL 1741 Communication Fiend
  19. OC 属性关键字
  20. 关于Linux DNS部分处理

热门文章

  1. Java包的基本概述
  2. RAMSPEED的简单测试数据 x86虚拟机 龙芯 飞腾
  3. IDEA下tomcat启动后 server乱码,Tomcat Catalina Log乱码问题的解决
  4. 【AtCoder】ARC067
  5. Junit测试类中如何调用Http通信
  6. swiper手滑动轮播图后自动轮播失效解决办法
  7. 第10章:深入浅出Ansible
  8. Antd中,Form和Select联合使用,导致placeholder不生效分析
  9. JArray
  10. C++反汇编第五讲,认识C++中的Try catch语法,以及在反汇编中还原