Output 0 or 1 based on array

I am not sure - what you mean. I thought it is a buffer. If it is a numeric array [0,0] or [1,1] it is even simpler as the switch does check if first and second element of the array is equal- I see no difference.

image

so a next switch must only differentiate between 0 and 1 on one bit - if both are equal the second one is the same.
If I use the false exit then I check also only one bit or field and know that the other one is the opposite.

That is why I asked to see the actual data right at the start, as the question was ambiguous. You can see from the debug that it is a numeric array not a Buffer.

It can certainly be done using core nodes, but I think that sometimes a few lines in a function node is a reasonable alternative to a collection of core nodes.

What do you think is the best core node solution for the problem given the posted data?

If this is a normal array - I would just use one switch node:

image

image

Strange as i see an array of objects in the data. So bits[0] and [1] would both be objects and should not be equal. But i do see it does not say object so i presume this is a debug array/buffer quirk.
[edit] So I just learnt that javascript allows Non numeric arrays ( Associative Arrays).

@mickym2 May be better to join the array's first two elements in the switch property with a JSONata expression, then do string comparisons on the outputs

Ok you mean something like this - many ways to Rome. :wink:

image

The value is not in msg.payload

I saw the original debug window - and saw that this was the output of the buffer node. Therefore I send some pictures how to change the buffer node -
If you use my picture in posting 13 then you can directly use numbers 1-3 -masking with the value of 3.

But anyway - is no problem . The thread creator has posted your code in #18 as solution and therefore our discussion is obsolete as your proposal seems to be the preferred solution.

1 Like

Your solution is valid and I took it into account, but for simplicity i feel the function block is better for me. However, I definitely learned about the switch/buffer node from your reply, so thank you.

I had not realised that there was already a buffer node involved. Your suggestion makes sense to me now. :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.