Skip to content

Instantly share code, notes, and snippets.

@oguzalb
Last active August 30, 2017 08:22
Show Gist options
  • Save oguzalb/6e2a5b4f3ba0024ca2e1973efd41fc20 to your computer and use it in GitHub Desktop.
Save oguzalb/6e2a5b4f3ba0024ca2e1973efd41fc20 to your computer and use it in GitHub Desktop.
map function javascript?!?
# Python
>>> map(int, ['10', '20', '30'])
[10, 20, 30]
# Clojure
user=> (map #(Integer/parseInt %) (list "10", "20", "30"))
(10 20 30)
# Scala
scala> Array("10", "20", "30").map(Integer.parseInt)
res4: Array[Int] = Array(10, 20, 30)
# Javascript
> ['10', '20', '30'].map(parseInt)
Array [ 10, NaN, NaN ]
@fatihacet
Copy link

@fatihacet
Copy link

fatihacet commented Aug 24, 2017

The correct usage should be

> ['10', '20', '30'].map(n => parseInt(n, 10))

@oguzalb
Copy link
Author

oguzalb commented Aug 30, 2017

just have seen the comments, thanks : )

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