Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
ES6, regex + Math max solution in Clear category for [old] Long Repeat by matejm
'use strict';
const assert = require('assert');
function longRepeat(string) {
const substrings = string.match(/(.)\1*/g) || [];
const lengths = substrings.map(substring => substring.length);
const maxLength = Math.max(...lengths);
return Math.max(maxLength, 0);
}
if (!global.is_checking) {
assert.strictEqual(
longRepeat('sdsffffse'),
4,
'First',
);
assert.strictEqual(
longRepeat('ddvvrwwwrggg'),
3,
'Second',
);
}
Dec. 24, 2018
Comments: