# Tag Info

0

One option is to ensure that the sales type is in (or not in) a white list of types using Array.prototype.includes() - for example: filteredSalesAgreementItems() { if (!['bricks', 'mortars'].includes(this.$route.query.salesType)) { return this.salesAgreementItems; } return this.salesAgreementItems.filter(obj => obj.department === this.$route....

2

Computed properties can return objects, which seems useful for you. computed: { filteredItems() { switch (this.\$route.query.salesType) { case 'bricks': return { filteredSalesAgreementItems: this.salesAgreementItems.filter(obj => obj.department === 'bricks'), subTitle: 'Bricks', title: 'Bricks' ...

2

The filtering of options logic can be simplified a bit. Instead of first checking that the product slot array exists and has a truthy length, just allow the array's .find method to handle empty arrays, using Optional Chaining to access this deeply into the product object. You can also merge the two logic branches by returning true when the conditions are not ...

0

The hardest thing about programming is creating a good project structure, but this is also the most important thing to get correct. Your project is structured well, and cleanly follows the model-view-controller structure, so great job! Your view logic is cleanly separated from the underlying model, and your controller is requesting updates on both the model ...

0

Get text before '?' with split('?').at(), then reverse it and get text before '/' and reverse it back ;) supplyUrl.split('?').at().split('').reverse().join('').split('/').at().split('').reverse().join('')

3

I think for any url related task you have two good tools as The URL API The URLPattern API With the URL constructor you may do like; var url = new URL("https://any-api/supplier/tariffSelectionG_E5449168?t=randomChars"), tariffCode = url.pathname.slice(url.pathname.lastIndexOf("/")+1); URLPattern API, on the other hand is ...

2

Using a Set You are best to use a Set to reduce the complexity that comes with Array.includes. Ignoring the sort. Your code has a complexity of $O(n^2)$ however using a set will reduce that to $O(n)$ Example of $O(n^2)$ dataA.filter(v => dataB.includes(v)); Example of same task with $O(n)$ complexity set = new Set(dataB); dataA.filter(v => set....

1

If you can, use the URL constructor. It is a bit clearer semantically: const supplyUrl = new URL("https://any-api/supplier/tariffSelectionG_E5449168?t=randomChars"); const parts = supplyUrl.pathname.split("/"); // the 0th item is empty since the pathname starts with a slash const tariff = parts[2];

4

While it may be unlikely to occur, the URL could contain a hostname with a top-level domain supplier. Currently .supplies is registered to Donuts Inc and someday URLs could have a TLD with supplier, which would lead the current code to not correctly find the target text. const supplyUrl = "https://my.supplier/supplier/tariffSelectionG_E5449168?t=...

5

Super short review; The code should handle the presence or the absence ? in a transparent way The code should probably check for /supplier/ instead of ? That leaves me with function extractTariffName(url){ const resource = '/supplier/'; if(url.contains(resource)){ return url.split('?').shift().split(resource).pop(); } //return undefined } ...

5

Avoid performing side-effects in the middle of a ternary expression. If you're not using the resulting value of the ternary operation, then you're using it wrong and should be using an ordinary if-then instead. Also, be consistent with your usage of semicolons, and let/const. const people = ['Chris', 'Anne', 'Colin', 'Terri', 'Phil', 'Lola', 'Sam', 'Kay',...

2

You can use the ascii code to understand the position in the alphabet. const findAlphabetIndex = (...chars) => { const base = 'a'.charCodeAt(0); return chars.map((char) => char.toLowerCase().charCodeAt(0) - base); }; console.log( findAlphabetIndex('a', 'A', 'b', 'z'), );

Top 50 recent answers are included