code: function toRanges(str) {
    var ranges = [], i;
  
    str = str.slice(1, -1);
  
    while (str.length) {
      for (i = 1; ; i++) {
        if (str[i] !== String.fromCharCode(str[i - 1].charCodeAt(0) + 1)) {
          if (i < 3) {
            ranges.push(str.slice(0, i));
          } else {
            ranges.push(str[0] + '-' + str[i - 1]);
          }
          str = str.slice(i);
          break;
        }
      }
    }
    return '[' + ranges.join('') + ']';
  }
docs: /*eslint-disable no-console /*eslint-env es6