Skip to content

Instantly share code, notes, and snippets.

@playpauseandstop
Created February 8, 2012 20:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save playpauseandstop/1773348 to your computer and use it in GitHub Desktop.
Save playpauseandstop/1773348 to your computer and use it in GitHub Desktop.
Hey, javascript! Are you fucking kidding me?!
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]
>> ['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]
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
)
> ["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]
@shemigon
Copy link

shemigon commented Feb 9, 2012

That's totally predictable and complies to parseInt specs :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment