Ad
  • Custom User Avatar

    The ~ operator is a bitwise operator, without going into to much detail, it simply inverts the binary bits of the expression in front of it. This is from the mozilla docs: 'Bitwise NOTing any number x yields -(x + 1). For example, ~-5 yields 4.'

    pin.indexOf('.') will return a -1 if the '.' is not in the pin. -1 is considerly a falsy value, so by using the bitwise NOT operator (~) on -1 the result equates to ~-1 = -(-1 + 1) = 0. And by using the logical NOT operator (!) it inverts the falsy value of 0 into a truthy value of 1.

    !~pin.indexOf('.') could be very easily replaced with something more readable like !pin.includes('.').

    I hope this makes sense.

  • Custom User Avatar

    Really like that the avg function is written as a separate, more generic function.

  • Custom User Avatar

    Wow! How is this not in the top of the solutions!?

  • Custom User Avatar

    Can you please explain what is going on in this code? Particularly I'm curious about this part

    !~pin.indexOf('.')

    I've read about tilde operator, but still cannot grasp the logic behind it in company with pin.indexOf('.')

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Wow, I have learnt something new about Python, thank you!