var TEST = function () { let _savePair; function _compareAndUpdate(newPair) { let newLen = newPair[1] - newPair[0] + 1; if (newLen > _savePair.len) { _savePair.pair = newPair; _savePair.len = newLen; } } return { exec: function (str) { let len = str ? str.length : 0; if (!len) { return ''; } _savePair = { pair: [0, 0], len: 1 }; let record = {}; let contPair = [0, 0]; record[str[0]] = 0; for (let i = 1; i < len; ++i) { let theChar = str[i]; if (contPair[0] <= record[theChar]) { _compareAndUpdate([ contPair[0], i - 1 ]); contPair[0] = record[theChar] + 1; } contPair[1] = i; record[theChar] = i; } _compareAndUpdate(contPair); return str.substr(_savePair.pair[0], _savePair.pair[1]+1); } }; }();