Performance issues aside, when would one be inclined to write a function like this "unoptimized" one?
An array literal inside a function that checks if the array contains an item is beyond contrived. Hence, I'm having trouble generalizing this pattern to something not contrived.
I tend to write lots of functions that reference a constant object in two situations currently. One is to check an argument against a list of types that have one response vs. a more common one. This avoids long IF clause with lots of ORs:
I use these all the time, mostly the latter, when I know there are particular front-end display requirements beyond the virgin data sent to me by the server. The former could also be used for permission or different content display booleans, etc.
2
u/nullified- Oct 09 '18
Performance issues aside, when would one be inclined to write a function like this "unoptimized" one?
An array literal inside a function that checks if the array contains an item is beyond contrived. Hence, I'm having trouble generalizing this pattern to something not contrived.