Answer the question
In order to leave comments, you need to log in
Is there a PL with a similar syntax for logical operations?
There was a dispute with a friend that he lacks expressions in JS like:
if (status === 'complete' || 'deleted' || 'updated') { //... }
if (status === 'complete' || status === 'deleted' || нувыпонели) {}
['complete', 'deleted', 'updated'].includes(status)
Answer the question
In order to leave comments, you need to log in
There is something similar in C#:
if(status is "complete" or "deleted" or "updated") { /*...*/ }
the syntax of the language should be as simple as possible
the simpler the better
do this:
let array_of_values = ['complete', 'deleted', 'updated']
let if = function(key, array_of_values)
{
return true /false
}
if( if(status , array_of_values) )
{ }
['complete', 'deleted', 'updated'].includes(status)
if (status === 'complete' || 'deleted' || 'updated') { //... }
If you optimize speed , then you need to use the power of hash tables, the search for which takes approximately O (1):
const NEEDED_STATUS = { complete: true, deleted: true, updated: true}
if (NEEDED_STATUS[status]) { /*... */ }
let is_complete = (status === 'complete');
let is_deleted = (status === 'deleted');
let is_updated = (status === 'updated');
if (is_complete || is_deleted || is_updated) { /*... */ }
is_что-то
are needed in other places in the code that will also look neat, and in general, the total amount of code can sometimes even decrease. VB.NET:
If (New String(){"111", "222", "333"}).Contains(status) Then
'...
End If
Select Case status : Case "111", "222", "333"
'...
End Select
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question