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.
thanks for ~~ explanations can be really useful
This comment is hidden because it contains spoiler information about the solution
I declared an object with the keywords (life, eating, kata etc.) as properties, and set their respective values (0, 1, 5) as laid out in the problem description.
IF for some reason when .map iterates over the array, and tries to look up a property that doesn't exist in the object, it would return undefined.
Anything added to undefined would be NaN
console.log(result + undefined); //NaN
console.log(100 + undefined); //NaN
simplified:
more examples:
All in all, I expected some test cases to include arrays that had unexepected elements.
~
is the bitwise flip operator. For example, the binary number0110
(6 in decimal) when flipped (each 0 flipped to a 1 and each 1 to a 0) will become1001
(-7 in decimal for two's complement, 9 for unsigned). If you flip bits twice, they return back to their original value......So, for a number,
~~
does precisely nothing. It can help guarantee you're working with a numeric value though, which is likely why the author is using it. For example:~undefined == -1
~-1 == 0
~~undefined == 0
This comment is hidden because it contains spoiler information about the solution