Number is double

Hello!

I have a CSV list with two values.

Is there a possibility to check whether a number is double in the second value.

here is an example.

TEST;123,124,124,125,126,

Result.

TEST = 124

try some thing like this

[{"id":"467f25b1.ab1b84","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"TEST;123,124,124,125,126,","payloadType":"str","x":150,"y":1460,"wires":[["180af757.068961"]]},{"id":"b1ce2d8c.07043","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"TEST;122,123,124,125,126,","payloadType":"str","x":150,"y":1540,"wires":[["180af757.068961"]]},{"id":"180af757.068961","type":"function","z":"bf9e1e33.030598","name":"","func":"let parts = msg.payload.split(\";\");\nlet number = parts[1].split(\",\");\nif(number[1] === number[2]){\n    msg.payload = parts[0] + \" = \" + number[1]\n}else{\n    msg.payload = parts[0] + \" = \" + \"not double\";\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":270,"y":1500,"wires":[["a77168c5af53b7ed"]]},{"id":"a77168c5af53b7ed","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":550,"y":1440,"wires":[]}]

Hello! Many thanks for your response.

Basically it works. But I can't say exactly where the double entries are.

Here is the correct data.

PRO3238-62;100131,100129,100050,
PRO3251-00;100132,100130,100042,100049,100042,
PRO3255-00;100132,100130,100042,100132,100049,
PRO1071-00;100166,100127,100103,100104,100105,100124,100070,100071,
PRO8175-02;100104,100105,100124,100070,100071,100116,100117,100104,

The PRO 8175-02 and PRO 3255-00 have duplicate entries.

That is not the question you asked

Is there a possibility to check whether a number is double in the second value.

so that is the question I answered.

Please be more definative in your questions

let parts = msg.payload.split(";");
let number_count = parts[1].split(",").reduce(function (acc, curr) {
  return acc[curr] ? ++acc[curr] : acc[curr] = 1, acc
}, {});
number_count = Object.keys(number_count).find(e => number_count[e]===2);
msg.payload = parts[0] + " = " + number_count
return msg;

apply that to each line of your cvs lines

[{"id":"697e7769.6da1d","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":1980,"wires":[["5e827651.98b828"]]},{"id":"5e827651.98b828","type":"template","z":"bf9e1e33.030598","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"PRO3238-62;100131,100129,100050,\nPRO3251-00;100132,100130,100042,100049,100042,\nPRO3255-00;100132,100130,100042,100132,100049,\nPRO1071-00;100166,100127,100103,100104,100105,100124,100070,100071,\nPRO8175-02;100104,100105,100124,100070,100071,100116,100117,100104,","output":"str","x":120,"y":2040,"wires":[["56b1aaa1.d9eed4"]]},{"id":"56b1aaa1.d9eed4","type":"split","z":"bf9e1e33.030598","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":260,"y":2040,"wires":[["7d9d8304.f8207c"]]},{"id":"7d9d8304.f8207c","type":"function","z":"bf9e1e33.030598","name":"","func":"let parts = msg.payload.split(\";\");\nlet number_count = parts[1].split(\",\").reduce(function (acc, curr) {\n  return acc[curr] ? ++acc[curr] : acc[curr] = 1, acc\n}, {});\nnumber_count = Object.keys(number_count).find(e => number_count[e]===2);\nmsg.payload = parts[0] + \" = \" + number_count\nreturn msg;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":410,"y":2040,"wires":[["d45cf4a0.3bf6d"]]},{"id":"d45cf4a0.3bf6d","type":"join","z":"bf9e1e33.030598","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":580,"y":2040,"wires":[["5e23abbc.866a3c"]]},{"id":"5e23abbc.866a3c","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":700,"y":1980,"wires":[]}]

Hello!

Thanks very much.

Goes really well

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