Scipion
Scipion

Reputation: 11888

How to extract a value from an Array of objects

I have an array of objects Foo :

let a, b, c = new Foo()
let l: Array<Foo> = [a, b, c]

evaluateFoo(f: Foo): boolean {
 ...
}

I am currently using a map to basically convert my list of Foo to an array of boolean (with the evaluteFoo function). Ultimately, what I want to get is either true or false --> either one of the evaluateFoo functions return true, or not, and I return false.

Currently, to do so I am first doing : l.map(f => evaluateFoo(f)) and then I go true the new array and do the check to see if one of the value is true.

As you understood this is tedious for something quite easy. Any other rxjs operator that could help me having something simpler ?

Upvotes: 2

Views: 434

Answers (1)

smnbbrv
smnbbrv

Reputation: 24541

Isn't that what you are looking for?

[1, 2, 3].some(e => e > 3)
> false
[1, 2, 3, 4].some(e => e > 3)
> true

where 1, 2, 3 are your Foos and e => e > 3 is your evaluation function

Upvotes: 2

Related Questions