Hello all,
i would need some help on a function to create a sequence check of multiple incomming booleans after each other:
e.g.:
I have 3 booleans that are incomming one after each other:
first message : msg.payload.valueBool = true
second message : msg.payload.valueBool = false
third message = msg.payload.valueBool = true
Based on that i would like to compare these message "sequence" with an defined sequence in a function node.
The function is currently looking like that:
var expectedSequence = [true, false, true];
var currentSequence = [];
function sequenceValidation(msg) {
var value = msg.payload.valueBool;
currentSequence.push(value);
if (currentSequence.length > expectedSequence.length) {
currentSequence.shift();
}
var sequenceCheck = JSON.stringify(currentSequence) === JSON.stringify(expectedSequence);
msg.payload.sequence_check = sequenceCheck;
msg.payload.sequence = currentSequence;
return msg;
}
newMsg = sequenceValidation(msg);
return newMsg;
Currently the Output looks like this, but the append / push operation to the array is not working and therefore the sequence check does not work:
{"_msgid":"14392d94b3744644","payload":{"valueBool":false,"sequence_check":false,"sequence":[false]},"topic":""}