News for hackers. Stuff that matters.
Re:Atom Shell is now Electron by coke12 on Thursday April 23, 2015 @05:15PM (#9429876)
It is wrong. "new Array(26)" creates an Array with preallocated space for 26 elements (instead of 26 'undefined' elements, as one might expect), and calling .map() on it will return another empty array. The semantics here are particularly difficult to reason about because map is specified to not execute its callback on undefined elements.

Someone will probably chime in here with a correction, but the point is this -- JS is NOT a friendly language to deal with.

Re:Atom Shell is now Electron by tracker1 on Thursday April 23, 2015 @09:29PM (#9430950)
It will iterate just fine, there are no values (undefined) for each `0` through `length-1`

    new Array(26).length === 26; //true
Re:Atom Shell is now Electron by disusered on Saturday April 25, 2015 @01:57AM (#9437406)
Seems like it doesn't, I recently read about this gotcha so I tested it out in JSBin. Using lodash map works as expected, though.

JSBin: http://jsbin.com/vasulumeti/1/edit?js,console

StackOverflow: http://stackoverflow.com/a/5501711/211291

Re:Atom Shell is now Electron by fcukhn on Thursday April 23, 2015 @06:21PM (#9430272)
Actually this code is very stupid and you're half correct. The standard built in Array methods like map or forEach don't work on implicitly defined undefined values but on explicit one they do.

For example: [1,2,3,undefined].forEach(ele => console.log(ele)) > 1 > 2 > 3 > undefined On the other hand: [1,2,3,,].forEach(ele => console.log(ele)) > 1 > 2 > 3

So, take the time you dedicate to hating JavaScript to understand the language instead of bitching here you and that stupid jerk above.