Array comparison fails #304

Open
opened 2026-02-20 10:16:17 -05:00 by deekerman · 7 comments
Owner

Originally created by @rogerl50 on GitHub (Jul 2, 2021).

The following clickRoutine:

  "clickRoutine": [
    {
      "func": "IF",
      "operand1": [],
      "relation": "==",
      "operand2": [],
      "thenRoutine": [
        "var equal = true"
      ],
      "elseRoutine": [
        "var equal = false"
      ]
    }
  ],

takes the else branch.

Originally created by @rogerl50 on GitHub (Jul 2, 2021). The following `clickRoutine`: ``` "clickRoutine": [ { "func": "IF", "operand1": [], "relation": "==", "operand2": [], "thenRoutine": [ "var equal = true" ], "elseRoutine": [ "var equal = false" ] } ], ``` takes the `else` branch.
Author
Owner

@robartsd commented on GitHub (Jul 2, 2021):

All object comparisons fail because we test === instead of ==.

@robartsd commented on GitHub (Jul 2, 2021): All object comparisons fail because we test `===` instead of `==`.
Author
Owner

@rogerl50 commented on GitHub (Jul 2, 2021):

So I guess I need to get the length of the array I'm comparing to [] and compare that to zero, unless there's a better way.

@rogerl50 commented on GitHub (Jul 2, 2021): So I guess I need to get the length of the array I'm comparing to `[]` and compare that to zero, unless there's a better way.
Author
Owner

@robartsd commented on GitHub (Jul 2, 2021):

So I guess I need to get the length of the array I'm comparing to [] and compare that to zero, unless there's a better way.

For now, yes. Discuss issue in #615.

@robartsd commented on GitHub (Jul 2, 2021): > So I guess I need to get the length of the array I'm comparing to `[]` and compare that to zero, unless there's a better way. For now, yes. Discuss issue in #615.
Author
Owner

@rogerl50 commented on GitHub (Jul 2, 2021):

Should this issue be linked to #615, or just closed?

@rogerl50 commented on GitHub (Jul 2, 2021): Should this issue be linked to #615, or just closed?
Author
Owner

@robartsd commented on GitHub (Jul 2, 2021):

I was mistaken IF does use == only SELECT is using === currently. But it looks like == does not return true for arrays unless they are the same object. Perhaps we should implement a deep comparison of objects as I believe we would like == to return true in this case.

@robartsd commented on GitHub (Jul 2, 2021): I was mistaken `IF` does use `==` only `SELECT` is using `===` currently. But it looks like `==` does not return true for arrays unless they are the same object. Perhaps we should implement a deep comparison of objects as I believe we would like `==` to return true in this case.
Author
Owner

@ArnoldSmith86 commented on GitHub (Jul 2, 2021):

Not sure. Another solution is to offer JSON stringify and parse and let the user compare that instead.

Doing that automatically in == might be OK though. The normal behavior is probably never useful for us.

@ArnoldSmith86 commented on GitHub (Jul 2, 2021): Not sure. Another solution is to offer JSON stringify and parse and let the user compare that instead. Doing that automatically in == might be OK though. The normal behavior is probably never useful for us.
Author
Owner

@robartsd commented on GitHub (Jul 2, 2021):

Of course for objects, JSON stringify could still be inadequate as the key order is not guaranteed. We might want to turn to something like https://github.com/substack/json-stable-stringify (could also be useful for TestCafe checks, but I don't think we've yet run into issues where key insertion order has caused problems there).

@robartsd commented on GitHub (Jul 2, 2021): Of course for objects, JSON stringify could still be inadequate as the key order is not guaranteed. We might want to turn to something like https://github.com/substack/json-stable-stringify (could also be useful for TestCafe checks, but I don't think we've yet run into issues where key insertion order has caused problems there).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/virtualtabletop#304
No description provided.