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.
This comment is hidden because it contains spoiler information about the solution
It's better to add in JavaScript tests a test with a huge number (e.g. "12345678912345"), because some solutions that use bitwise operations:
var stringToNumber = function(str){
return str|0; // or ~~str (or str^0)
}
may work incorrectlly on huge numbers.
For example:
str = "12345678912345"
str|0 // 1942903641
This happens because in JavaScript bitwise operations convert it arguments to 32-bit integers. In this example binary representation of number in str is more than 32 bit, therefore it is truncated.
The error you mentioned above occures in Python3.x, while in Python2.x this code executes correctly.
The behaviour of map function is different in Python2.x and Python3.x:
"map" in Python2.x: https://docs.python.org/2/library/functions.html#map
"map" in Python3.x: https://docs.python.org/3/library/functions.html#map
Thank you for rising this question! Now I know that this code is tricky one and not compatible with version 3.x
This code may work incorrectlly on some inputs.
For example:
This happens because bitwise operations convert it arguments to 32-bit integers. In this example binary representation of number in str is more than 32 bit, therefore it is truncated.
So you should use this code only, if you are sure, that all numbers that you pass in your function fit 32-bit.
This comment is hidden because it contains spoiler information about the solution
Thank you for your remark! I've rectified this mistake.
Thank you for your suggestions! I've edited the description and tests. Hope I've fixed all that you had mentioned before.