Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

For better results start at -1 '-1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20'.split(' ').map(parseInt) gets you

    [
      -1, NaN, // could be better
      1,  2,  3,  4,  5,  6,  7,  8,  9, // ok a little bumpy at the start but now we're cookin'
      11,  13, 15, 17, 19, 21, 23, 25, 27, 29, // not great not terrible
      42 // dang
    ]
way closer.

Pretty sure the Number constructor was made to get you around this. map(Number) does what you would expect.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: