Timeline for answer to javascript : filter array of objects using another array as filter by mhodges
Current License: CC BY-SA 3.0
Post Revisions
7 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| May 22, 2017 at 15:09 | comment | added | mhodges |
@NeverGiveUp161 If === -1 gives you the unmatched, and "not unmatched" gives you matched, then not === -1 (AKA !== -1) will give you the matched. You can also say > -1 to save a couple keystrokes. Or even fancier, ~query.indexOf(...) The tilde operator does a bitwise NOT, and only returns false if the value is equal to -1, and returns true for everything else. Which in the case of indexOf() is actually perfect (it is just more ambiguous as to what the code is doing)
|
|
| May 22, 2017 at 11:53 | comment | added | NeverGiveUp161 | @mhodges: This filters the unmatched element,any idea on matched? this part === -1 | |
| May 19, 2017 at 15:52 | comment | added | mhodges | @zfrisch I wasn't the one asking about the downvotes, however. lol someone came by and downvoted every answer and then left - it happens occasionally for no reason. I know my solution is beneficial to the OP, so I'm not too worried about it. | |
| May 19, 2017 at 15:50 | comment | added | mhodges | @zfrisch I agree, my attempt was to keep the code as close to the OP's original code as possible. | |
| May 19, 2017 at 15:40 | comment | added | Nope | @doutriforce There is nothing wrong with the answer and I didn't downvote and I don't disagree with you at all that it could be helpful but as I said, I assume who ever downvoted did not find the answer useful and they don't have to explain why as I'm sure they would have left a comment already if they felt it was worth it to them. | |
| May 19, 2017 at 15:36 | comment | added | zfrisch | There's nothing wrong with this answer, and I personally didn't downvote it. My guess is you might be getting downvotes due to the fact that it isn't following a functional paradigm. | |
| May 19, 2017 at 15:14 | history | answered | mhodges | CC BY-SA 3.0 |