Created
February 8, 2012 20:38
-
-
Save playpauseandstop/1773348 to your computer and use it in GitHub Desktop.
Hey, javascript! Are you fucking kidding me?!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In [1]: map(int, ('00', '01', '02', '03', '04', '05', '06', '07', '08', '09')) | |
Out[1]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> ['00', '01', '02', '03', '04', '05', '06', '07', '08', '09'].map! {|x| Integer(x)} | |
ArgumentError: invalid value for Integer: "08" | |
from (irb):1:in `Integer' | |
from (irb):1 | |
from (irb):1:in `map!' | |
from (irb):1 | |
>> ['00', '01', '02', '03', '04', '05', '06', '07', '08', '09'].map! {|x| Integer(Float(x))} | |
=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
php > print_r(array_map(intval, array('00', '01', '02', '03', '04', '05', '06', '07', '08', '09'))); | |
Array | |
( | |
[0] => 0 | |
[1] => 1 | |
[2] => 2 | |
[3] => 3 | |
[4] => 4 | |
[5] => 5 | |
[6] => 6 | |
[7] => 7 | |
[8] => 8 | |
[9] => 9 | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09"].map(parseInt); | |
[0, NaN, 0, 0, 0, 0, 0, 0, 0, 0] | |
> ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09"].map(function(item) { return parseInt(item); }); | |
[0, 1, 2, 3, 4, 5, 6, 7, 0, 0] | |
> ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09"].map(function(item) { return parseInt(parseFloat(item)); }); | |
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That's totally predictable and complies to
parseInt
specs :)