New answers tagged

0

There are multiple ways to convert from one string to another, but the function doesn't always find the one with the least edits. Try for example, aaaba and aaba. One a has been added to the beginning, but the function returns false. In general, trying to count the number of edits would require quadratic time as it's the Levenshtein distance but it can be ...


0

Your approach will take you to the solution but as you already noticed it is quite fragile. If I will ask you to make amends to your code or gave you an extended problem, it would be hard to make those changes. There are too many conditions that are hard to understand and makes code a bit of a hassle. Instead, if you think of all the requirements as an ...


1

Your questions: You could use BaseAnimal, but that would only give you the base properties. There's no way I know of to make this work other than casting, but that would make it unsafe. The discriminated union is quite nice imo, it's very easy to understand. Since typescript is just types, there is no way for it to actually set a value on an object. You'd ...


3

You don't need to create a new promise for each call. A promise can be reused multiple times, so all you have to do is cache the promise. Something like this: if (bottles.has(key)) { return bottles.get(key) } const p = neck(...args).finally(() => { bottles.delete(key) }) bottles.set(key, p) return p


0

What I would suggest is to wrap createStackNavigator in another function where you mimic the api but with different defaults.


3

Define types If you are using a typed language like TypeScript, you should use it correctly. Defining most of the variables as type any does not give you robust type protection. Using TypeScript this way is just bloating your code with noise. Low quality Sorry to say this, but the code is rather low quality. The code has a lot of repeated and some redundant ...


4

The first thing I would extract is the condition: const includesTourData = (tours, steps, tour) => tours.includes(tour?.openTour) && steps.includes(tour?.stepIndex) && const handleJoyrideDock = (dispatch: any, tour: any, index: number) => includesTourData(arrTourDock, arrStepsDock, tour) && JoyRideDelayContinue(...


3

Defaults & Ternaries There is nothing wrong with statements. However Javascript and most C like languages allow a wide variety of branching styles. For example you can default the navigation, and use a ternary ? (Conditional operator) to select the redirect option. This has only 1 statement if to allow the local storage key to be set. The default ...


Top 50 recent answers are included