Let's assume that I have a 2D array in typescript. Exactly in the source code it looks like this:
tsvData: any;
this.tsvData = this.UploaderService.tsvData.split("\n").map(function(row){return row.split("\t");});
I would like to change the length of each table to be equal to the longest one provided that the longest one has a length greater than or equal to 5. If the length of the longest table is less than 5 I would like to change the length of each table to 5. I would like to fill the missing places with an empty string. I add two examples for understanding what my goal is. In addition, I would like to delete all arrays with empty strings.
Example 1
In this example the longest array is equals to 4 so I change the length of each table to 5.
Input:
[["text1", "text2", "text3", "text4"],
["text5", "text6"],
["text7"],
["text8", "text9", "text10"],
[""]]
Output:
[["text1", "text2", "text3", "text4", ""],
["text5", "text6", "", "", ""],
["text7", "", "", "", ""],
["text8", "text9", "text10", "", ""]]
Example 2
In this example the longest array is equals to 6 so I change the length of each table to 6.
Input:
[["text1", "text2", "text3", "text4"],
["text5", "text6"],
["text7"],
["text8", "text9", "text10", "text11", "text12", "text13"],
[""]]
Output:
[["text1", "text2", "text3", "text4", "", ""],
["text5", "text6", "", "", "", ""],
["text7", "", "", "", "", ""],
["text8", "text9", "text10", "text11", "text12", "text13"]]