1

Consider the following two objects:

const ReductionMap = {
  '10': 10.5,
  '1000': 20.5,
}

const initialValues = {
  '10': 110,
  '1000': 120,
}

Using lodash v4.17.5 (here _), we reduce initialValues to a new object where each values has been reduced by the corresponding value in ReductionMap:

const reducedValues = _.reduce(
  initialValues,
  (acc, value, key) => ({
    ...acc,
    [key]: value - ReductionMap[key],
  }),
  {}
)

What we would expect to get here would be

{ '10': 99.5, '1000': 99.5 }

but in mobile Safari on iOS 10.3.2 I am getting:

{
  '0': NaN,
  '1': NaN,
  '2': NaN,
  '3': NaN,
  '4': NaN,
  '5': NaN,
  '6': NaN,
  '7': NaN,
  '8': NaN,
  '9': NaN,
  '10': 99.5,
  '11': NaN,
  '12': NaN,
  '1000': 99.5,
}

Here are some observations:

  • Changing the key '10' to '20' or '100' yields an object with keys from 0 up to key + 4 and then '1000'.
  • Examples of combinations of keys that do work are '999', '1000', '900', '1000' and '2000', '1000'.
  • Rounding the calculated value to an integer produces valid results.

I created a pen on CodePen where you can try out this phenomena.

Can anyone explain what is happening here?


Note: I'm not looking for ways to get around this issue, only to understand why this is happening.

Alexander Wallin
  • 1,394
  • 10
  • 22
  • 1
    [What version of LoDash are you using?](https://github.com/lodash/lodash/issues/1033) – Pointy Mar 19 '18 at 15:37
  • Is working as expected! – Ele Mar 19 '18 at 15:38
  • @Pointy v4.17.5. I've added it to the question. – Alexander Wallin Mar 19 '18 at 16:16
  • @Ele On what iOS version is it working for you? – Alexander Wallin Mar 19 '18 at 16:16
  • @AlexanderWallin interesting. Well the description of the behavior from that linked Github bug (and the other one linked from in there) sure seem similar to what you're seeing. I can't see how that's anything but a platform bug. – Pointy Mar 19 '18 at 16:47
  • [You might see if tricks to disable JIT for that piece of code make a difference](https://stackoverflow.com/questions/13147026/disabling-jit-in-safari-6-to-workaround-severe-javascript-jit-bugs), at least as an experiment. – Pointy Mar 19 '18 at 16:49

0 Answers0