0

I have seen in a codebase instances of the (simplified version) of the following code:

//testIds is a calculated array of ids stored in a variable

let existence = tests.filter( (test) => return !!~testIds.indexOf(test.id) )

I have no idea what !!~ is, to me it looks like it's a more verbose way of saying:

testIds.indexOf(test.id) > 0

Can someone tell me what this is?

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
Conqueror
  • 4,265
  • 7
  • 35
  • 41
  • it checks if the value != -1 – dave Jun 02 '15 at 20:21
  • the `~` does a bitwise not, then the `!!` coalesces the value to a boolean, so you end up with the bitwise negation of your input, coalesced to its "truthy" representation – chiliNUT Jun 03 '15 at 01:35

0 Answers0