Sum of values in nested lists using FormulaMap()

Hi, there

I have the nested list below:
[[A,1],[B,2],[C,3]]

If I want to get the sum of the second values of each list, the formula I use is:

List(List("A",1),List("B",2),List("C",3)).FormulaMap(CurrentValue.Nth(2)).Sum()

The thing is this formula returns the right result but with the error message bellow.

Am I doing something wrong? Is there another way of doing this?
I’m assuming it’s a bug. For instance, if I used .count() instead of .sum() you don’t get the same error message.

Well, here’s two things happening, all because of how Coda (and Javascript) lack strict type system.

  1. Coda is trying its best to infer data types where possible. In this case though, Coda cannot guarantee that each CurrentValue.Nth(2) is indeed going to be a number (and Sum() expects all values to be numbers.) Maybe it simply doesn’t inspect nested lists and assumes mixed type (“a list of unknown values”) with no affinity. That’s why it raises that error.

  2. Calculation still goes through because Javascript doesn’t care whether functions/operators receive arguments of correct type — it performs a “leap of faith” calculation hoping that all inputs will be of correct type or could be converted into expected type (hence all those “wtf js” memes)

If that error bothers you, try writing CurrentValue.Nth(2).ToNumber()

5 Likes