Loosely inspired by how much people seemed to enjoy a similar question I asked on Games about unappreciated titles. But answers don’t have to be media related (they still can be though).

  • mindbleach
    link
    fedilink
    arrow-up
    2
    ·
    1 year ago

    Javascript arrays begin empty, even when sized, and in a way that’s different from NaN. If you do new Array(12).map( (value, index) => index ) to get a counting list, you get… nothing. .map() does not iterate over those indices. But if you do new Array(12).fill(0).map( (value, index) => index ) then it works. .fill() does iterate over those values. Why? Because screw you, that’s why.

    If you examine the empty array in the console, it reports “12 empty slots,” and all values come back as “undefined.” But if you pass it through JSON.stringify, those all become nulls. Why aren’t they nulls in the first place? See previous answer.

    • Hamartiogonic@sopuli.xyz
      link
      fedilink
      arrow-up
      2
      ·
      1 year ago

      Never done anything with javascript, but it sounds like a lot of fun, just like writing VBA in Excel. You know, there’s a reason why I tend to move my calculations to R as soon I can see that Excel is about to consider giving me headaches.