I have a csv file with a bunch of numbers ranging from 500 to 500,000 and would like to replace the matches with 1 and mismatches by shifting the mismatched content to right simultaneously shifting the rest of the columns to right but leaving the top row untouched and then replacing the empty spaces in that column with 0 so that I have a fixed length matrix, for instance, I have the following:
12345,6457,789,21231,657
6457,21231,657
12345,789,21231
When I search for the string 12345 in the first column replace the matched cells (row 1 column 1 and row 3 column 1) with 1 and mismatched cell (row 2 column 1) with a 0 and comma after pushing the second row to the right..see below:
1,6457,789,21231,657
0,6457,21231,657
1,789,21231
Now when I search for the next string (6457) in the second column perform the same steps as above, that is, replace the matched cells (row 1 column 2 and row 2 column 2) with 1 and mismatched cell (row 3 column 2) with a 0 and comma after pushing the third row to the right ..see below:
1,1,789,21231,657
0,1,21231,657
1,0,789,21231
and so on until I have the desired output as follows:
1,1,1,1,1
0,1,0,1,1
1,0,1,1,0,
Below is a link to the sample file.
Thanks
1
, resulting in1,456,7892
. Following your logic I'm arriving at a different output to yours:[1, 1, 1, 1] [0, 0, 0] [1, 0, 0] [0, 0, 0]
. Also, is it absolutely necessary to involve regex or is doing this in pure JavaScript fine?