I'm looking to identify the longest substring within a given string.
const str = "aassqwertybbvvqwertyuivv";
const longestSubstring = str.split("").reduce((prevValue, currValue, index, arr) => {
let substr = ""
if (prevValue !== currValue) {
substr = currValue + substr;
}
return substr;
}, "");
console.log(longestSubstring)
The expected output is 8 (qwertyui).
Currently, it only provides me with the last substring found.