Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Integer value and IN operator
Message
De
13/03/2016 05:06:49
 
 
Information générale
Forum:
Javascript
Catégorie:
Autre
Divers
Thread ID:
01632871
Message ID:
01632950
Vues:
62
>The Items table is not well normalized, it has 6 columns for profit centers and 28 for prices. In any case, that is how it's defined and it's not going to change overnight, so I'm working with what I have.

As you are working with the stuff IAC, refactoring should be thought about.
>
>I know the syntax Thierry mentioned. Do you mean I should have written the check using a loop instead?

To be more to the point, an outer and an inner loop, which for me is 2 loops if you ***create*** unrolled code with normal code, 1 loop if you just execute the check similar to the code Antonio has given which cancels the need for the inner loop by sorting the array. Speed of sorted approach vs. 2 loops depending on the data, probably irrelevant. Generator pattern not necessary IMO.

The long coded part is manual loop unrolling, using the magic number 6. If this is not a premature, therefore unneccessary optimization, such unrolling code should ALWAYS be ***created*** by function using the magic number as upper bound of the iterator well marked either in a loop or in a generator, but never just coded as such. With looping code the bad/faulty normalization is still visible AND easy to fix, whereas the posted unrolled code makes fixing the data model more expensive and is much harder to maintain while also 3 additional profit centers will create more work than necessary if managment still disallows a data model fix and forces item.prCtr7, item.prCtr8, item.prCtr9.

Such code is making a bad situation worse.


>
>>I think I already pointed you once to the syntax Thierry hints at ;-)
>>Even then, having variable item.prCtr1 .. item.prCtr6 in an object smells like repeating values of a record, with all the arguments of data normalizition speaking against it - are you certain that those profit centers would not be better represented in a list-like structure instead of properties with number mangling in the property name ? In Javascript probably easiest as a stack or queue, which could be expressed as a collection/array, while linked lists seem a better fit for languages where you handle memory (pointers) yourself
>>
>>>
>>>https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/in
>>>
>>>I am writing a function for checking profit centers. An item can have 6 profit centers. The values are saved as item.prCtr1, item.prCtr2, etc.
>>>I want to make sure that if they are specified (e.g. not 0/null), then they are all different.
>>>So, I am going to write like this
>>>
>>>
>>>if (item.prCtr1!=0 && item.prCtr1 in new Array(item.prCtr2, item.prCtr3, item.prCtr4, item.prCtr5, item.prCtr6) )
>>>
>>>The problem here that according to that reference, it will also compare with the array's index and so I may get false positives.
>>>Do you see a way to write the above code in a simple manner? Or I'd rather write 5 OR checks for all 6 of them?
>>>What do you think?
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform