The below code scans a string and returns the length of the largest substring containing all unique characters. I am iterating over the input string's characters and analyzing the longest unique charactered substring ending at the current character. By caching some info about the longest substring ending at the PREVIOUS characters, we can quickly make statements about this one.I am not too concerned about the logic or runtime of this code, as I am only starting to get back into my interview prep. I am more concerned this code does not look javascript enough for more seasoned javascript developers. Coming from an OOP (Java, C#, typescript) background, I might be trying to force certain structures onto the code that might not be suitable.let LongestSubstringNoRepeats = function (s) {    let currSubstring = {        length: 1,        substring: s[0],    }    currSubstring.chars = {};    currSubstring.chars[s[0]] = true;    let currMax = 1;    for (let i = 1; i < s.length; ++i) {        if (currSubstring.chars[s[i]]) {            //repeat character            let substring = currSubstring.substring;            let index = substring.indexOf(s[i]);            substring = substring.slice(index + 1);            newChars = {} ;            substring.split().map((char) => {                newChars[char] = true;                });            currSubstring.substring = substring;            currSubstring.chars = newChars;            currSubstring.length = substring.length;        } else {            currSubstring.length++;            currSubstring.substring = currSubstring.substring.concat(s[i]);            currSubstring.chars[s[i]] = true;        }        if (currSubstring.length > currMax){            currMax = currSubstring.length;        }    }    return currMax;}
Find length of largest substring with unique characters
javascript
I am more concerned this code does not look javascript enough There's no such thing as javascript enough. If that meant anything, for me it would be keeping it simple. The best code is one that's written in a way that you never have to run to debug. Errors will show themselves voluntarily.returns the length of the largest substringBut your function isn't named that way. It's named LongestSubstringNoRepeats which sounds like it returns the substring, not the length. Always name appropriately. Do not give ambiguous or confusing names. It may be popular among devs that naming is one of the two hardest problems in computer science, but that only happens because it's a detail easily missed.substring.split().map((char) => {  newChars[char] = true;    });Never use functions outside their intended purpose. array.map is intended to create another array based on the values of an existing array, a 1:1 transform. In this case, you used it as a loop. If you intend to do that, use array.forEach instead.Also, avoid unnecessary creation of objects. In this case string.split creates an array, array.map also creates another. This operation is probably possible using only string manipulation.let currSubstring = {    length: 1,    substring: s[0],}currSubstring.chars = {};currSubstring.chars[s[0]] = true;// tolet currentSubString = {  length: 1,  substring: s[0],  chars: { [s[0]]: true }}Can be shortened by using computed property names.One way to check for repeats is to use Set. It's like an array, but will only hold unique values. Once you add in something that already exists, Set never changes size - something you can check if a character already repeated.Always name your variables fully and explicitly. Abbreviations should be avoided as it will only cause headaches down the road. JS can be compressed with tools so code size is never an issue. Write for a human, not for the machine.Always provide test cases. In this case, just looking at the code doesn't give me the impression that it works. It may not work at all or has edge cases you never thought of. TDD is always a good start, especially for API-ish code/code that doesn't involve anything else other than a function that returns a value.