First off, sorry if the title is not 100% accurate.
I have a problem.
I have a dynamic list of items in List A, the number of items can be anywhere between 1-50:
item1
item2
item3
I need a function that loops through these items checking if a condition is true to each of these items like so:
if(item1 && condition) continue
What is the best way to go about creating this function/algorithm? As the list is not static I cannot hardcode the conditions like so:
if(item1 && condition) continue
if(item2 && condition) continue
if(item3 && condition) continue
Thanks in advance
Edit: I want the function to return true if at least one of the conditions is true.
Use Array#some
.
The
some()
method tests whether at least one element in the array passes the test implemented by the provided function. It returns true if, in the array, it finds an element for which the provided function returns true; otherwise it returns false. It doesn't modify the array.
let result = arr.some(element => predicate(element));