What the actual fuck did I just witness. What the fuck do you mean map passes the array as three argument to one parseInt call ? Why the fucking kind of DIY bullshit reason would I want/need a full-fledged enumaerator along with the array element and break abstraction ???
So the "correct" way to pass an array of int to parseInt would be to add a wrapper to remove the data added by the function that unwraps the array ? ["1", "2", "3"].map((num,idx,arr) => parseInt(num)) ?
God I'm glad I don't have to work with this abomination of a language. They'll have to take my [int(x) for x in array] from my cold dead hands.
No need to add idx and arr if you're not going to use those. Optional parameters.
["1", "2", "3"].map(x=>parseInt(x)) //[1, 2, 3]
Edit, you can also do
["1", "2", "3"].map(x=>Number(x)) //[1, 2, 3]
Number() converts the entire thing to a Number type (aka a Double). Usually the same thing, not so when letters are involved. parseInt("20px") returns 20, Number("20px") returns NaN. Use whatever makes most sense to you. :)
View all comments
Show parent comment
1
u/HeKis4 Sep 25 '26 edited Sep 25 '26
What the actual fuck did I just witness.
What the fuck do you mean map passes the array as three argument to one parseInt call ?Why the fucking kind of DIY bullshit reason would I want/need a full-fledged enumaerator along with the array element and break abstraction ???So the "correct" way to pass an array of int to parseInt would be to add a wrapper to remove the data added by the function that unwraps the array ?
["1", "2", "3"].map((num,idx,arr) => parseInt(num))?God I'm glad I don't have to work with this abomination of a language. They'll have to take my
[int(x) for x in array]from my cold dead hands.