# Workings of the Smooth node

Hi all,
I was looking for a rolling average over time, but it seems smoothing the values might do the trick.
Now what i'm wondering is some of the working of the node.
I already found out that it can only process numbers. And that if the string contains a number, it should be working as well.

Now; what triggers the smooth node? If set to "most recent 2 values" will it only produce a value after the second?

And what if you only point it's property to msg.payload? Should it then handle all the incoming numbers?

I've got a payload containing two values. But when i dont point it towards the actual value, it wont work.

So property msg.payload.svalue1 is working
but msg.payload isnt. Is that supposed to be the case?

Also; when a string value is picked up by the node it is converted to number. Wouldn't it be easier to keep it as it was?

Javascript cannot do arithmetic on a string. The node is kind enough to think to itself "this flow has foolishly passed me a string and asked me to do arithmetic with it, rather than throw an error I will, out of the goodness of my heart, convert it to a number on the assumption that is what the flow wants me to do."

2 Likes

An example of why it cannot do arithmetic on a string is to consider the two string values "12" and "3". If asked to sort those two, lowest first, then which one should come first?
Before answering, consider the strings "ab" and "c" If asked to sort those two which should come first? The answer is "ab" as "a" comes before "c".
The result is that if you sort the strings "12" and "3" then "12" comes first, as the character "1" comes before "3"! Therefore javascript has to know whether a value is a Number or a String. It cannot make assumptions.

1 Like

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