第 1 种方法

String.prototype.getMostString = function() {
  var str = this;
  var maximumTime = 0,
      maximumString;

  while(str) {
    var tempString = str.charAt(0);
    var tempStr = str.split(tempString);
    var tempTime = str.length - (str = tempStr.join('')).length;
    if (tempTime > maximumTime) {
      maximumTime = tempTime;
      maximumString = tempString;
    }
  }

  return {'maximumString': maximumString, 'maximumTime': maximumTime};
}

第 2 种方法

String.prototype.getMostString = function() {
  var str = this;
  var obj = {},
      maximumTime = 0,
      maximumString;

  for (var i = 0; i < str.length; i++) {
    var char = str.charAt(i);
    if (!obj[char]) {
      obj[char] = 1;
    } else {
      obj[char]++;
    }
  }

  var arr = [];
  for (var key in obj) {
    arr.push(obj[key]);
  };
  var maximumTime = Math.max.apply(null, arr);

  // ES6 的方法
  // let arr = Object.values(obj);
  // let maximumTime = Math.max(...arr);

  for (var key in obj) {
    if(obj[key] === maximumTime) {
      return {'maximumString': key, 'maximumTime': maximumTime};
    }
  }
}

第 3 种方法

String.prototype.getMostString = function() {
  var str = this;
  var obj = {},
      maximumTime = 0,
      maximumString;

  for (var i = 0; i < str.length; i++) {
    var char = str.charAt(i);
    if (!obj[char]) {
      obj[char] = 1;
    } else {
      obj[char]++;
    }
  }

  // var maximumTime = Math.max.apply(null, Object.values(obj));
  // 或者:
  var maximumTime = Math.max(...Object.values(obj));

  var maximumString = Object.keys(obj).reduce(function(a, b){
    return obj[a] > obj[b] ? a : b;
  })

  return {'maximumString': maximumString, 'maximumTime': maximumTime};
}

#