angular-ngrx-refactoring icon indicating copy to clipboard operation
angular-ngrx-refactoring copied to clipboard

Filter not working

Open epamer opened this issue 5 years ago • 0 comments

Hi,

I have found a mistake in your code.

Please, consider this statment: .filter((n: any) => { return n.payload.event.url.indexOf('flight') })

The indexOf method returns the index of the element or -1 if the element not exists. However, your filter expects a boolean value (true or false), so under the hood, the value will be converted to boolean. But if you check Boolean(-1) it returns true. Therefore this filter will always return true.

To make it works you have to compare it with -1: .filter((n: any) => n.payload.event.url.indexOf('flight')) !== -1

epamer avatar Jan 26 '20 13:01 epamer