Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
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.
Really like that the avg function is written as a separate, more generic function.
Wow! How is this not in the top of the solutions!?
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('.')
This comment is hidden because it contains spoiler information about the solution
Wow, I have learnt something new about Python, thank you!