You don't really need to write a function, you can use 2 standard nodes;
- join node - to combine both messages into an array
- change node with a jsonata expression to select the lowest number in the array
[{"id":"9b80fac1.4d62e8","type":"join","z":"dbe9689e.fc98f8","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":295,"y":790,"wires":[["9d32943.7172068"]]},{"id":"f53d49.5158e2b8","type":"inject","z":"dbe9689e.fc98f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"2","payloadType":"num","x":145,"y":765,"wires":[["9b80fac1.4d62e8"]]},{"id":"b4903047.af082","type":"inject","z":"dbe9689e.fc98f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"5","payloadType":"num","x":142,"y":811,"wires":[["9b80fac1.4d62e8"]]},{"id":"9d32943.7172068","type":"change","z":"dbe9689e.fc98f8","name":"change","rules":[{"t":"set","p":"payload","pt":"msg","to":"$min(payload)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":435,"y":790,"wires":[["c2d9cbe7.35c678"]]},{"id":"c2d9cbe7.35c678","type":"debug","z":"dbe9689e.fc98f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":790,"wires":[]}]
EDIT - flow updated to include $min(payload)
as @E1cid's better suggestion below.