How can I change the length of each table to be equal to the longest one provided that the longest one has a...
up vote
2
down vote
favorite
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"]]
arrays angular typescript multidimensional-array angular6
add a comment |
up vote
2
down vote
favorite
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"]]
arrays angular typescript multidimensional-array angular6
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
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"]]
arrays angular typescript multidimensional-array angular6
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"]]
arrays angular typescript multidimensional-array angular6
arrays angular typescript multidimensional-array angular6
edited yesterday
asked yesterday
thedbogh
708
708
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
Let's break it down into steps:
- Find the max length in the arrays of the 2D array.
- Check if it's
>= 5
. Based on this, create amaxLength
. - Then loop through the 2D array, create the rest array and fill it with
""
. - Merge the rest array with each item of the 2D array.
Try this:
var initialTime = performance.now();
var array1 = [
["text1", "text2", "text3", "text4"],
["text5", "text6"],
["text7"],
["text8", "text9", "text10"],
[""]
];
var array2 = [
["text1", "text2", "text3", "text4"],
["text5", "text6"],
["text7"],
["text8", "text9", "text10", "text11", "text12", "text13"],
[""]
];
function fillRestItems(arrays) {
var maxArrayLength = Math
.max(...arrays.map(array => array.length));
var maxLength = maxArrayLength >= 5 ? maxArrayLength : 5;
return arrays
.map(arr => {
if(!(arr.length === 1 && arr[0] === "")) {
var addedArray = new Array(maxLength - arr.length).fill("");
return [...arr, ...addedArray];
}
})
.filter(array => array !== undefined);
}
console.log('Filled Array 1:', fillRestItems(array1));
console.log('Filled Array 2: ', fillRestItems(array2));
var finalTime = performance.now();
console.log(`This took: ${(finalTime - initialTime)} ms`);
This is almost what I wanted to achieve, however in the case of[""]
it returns["", "", "", "", ""]
but it should remove this array.
– thedbogh
yesterday
Thank you, both yours and the Sid's solution work perfectly. Of course, I voted for both, but I can only accept one. I must choose in that case a solution with better performance. Which one do you think is better?
– thedbogh
yesterday
Yes, I updated the question. Thank you for your help.
– thedbogh
yesterday
I made a mistake. I didn't check a case when the longest array in the table is shorter than 5. Your solution works properly unfortunately Sid's is not. I accept your solution.
– thedbogh
yesterday
add a comment |
up vote
1
down vote
First step would be to find the sub-array of maximum size.
let arr = [["text1", "text2", "text3", "text4"],
["text5", "text6"],
["text7"],
["text8", "text9", "text10"],
[""]];
arr = arr.filter(e => e.every(x => x !== ""))
const maxLength = Math.max(...arr.map(a => a.length));
The next step is to fill the array with blank values.
arr.forEach(e => {
while(e.length < maxLength){
e.push("");
}
});
console.log(arr);
I am sure there are better ways of doing it as the time complexity of the algorithm is O(n2)
This is almost what I wanted to achieve, however in the case of[""]
it returns["", "", "", "", ""]
but it should remove this array.
– thedbogh
yesterday
Fixed the code to filter unwanted items.
– Sid
yesterday
Thank you, both yours and the SiddAjmera's solution work perfectly. Of course, I voted for both, but I can only accept one. I must choose in that case a solution with better performance. Which one do you think is better?
– thedbogh
yesterday
Go with whoever answered first . ;)
– Sid
yesterday
I made a mistake. I didn't check a case when the longest array in the table is shorter than 5. In your case it doesn't work. Performance in both cases is similar so in accordance to your suggestion I accept the solution of SiddAjmera.
– thedbogh
yesterday
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Let's break it down into steps:
- Find the max length in the arrays of the 2D array.
- Check if it's
>= 5
. Based on this, create amaxLength
. - Then loop through the 2D array, create the rest array and fill it with
""
. - Merge the rest array with each item of the 2D array.
Try this:
var initialTime = performance.now();
var array1 = [
["text1", "text2", "text3", "text4"],
["text5", "text6"],
["text7"],
["text8", "text9", "text10"],
[""]
];
var array2 = [
["text1", "text2", "text3", "text4"],
["text5", "text6"],
["text7"],
["text8", "text9", "text10", "text11", "text12", "text13"],
[""]
];
function fillRestItems(arrays) {
var maxArrayLength = Math
.max(...arrays.map(array => array.length));
var maxLength = maxArrayLength >= 5 ? maxArrayLength : 5;
return arrays
.map(arr => {
if(!(arr.length === 1 && arr[0] === "")) {
var addedArray = new Array(maxLength - arr.length).fill("");
return [...arr, ...addedArray];
}
})
.filter(array => array !== undefined);
}
console.log('Filled Array 1:', fillRestItems(array1));
console.log('Filled Array 2: ', fillRestItems(array2));
var finalTime = performance.now();
console.log(`This took: ${(finalTime - initialTime)} ms`);
This is almost what I wanted to achieve, however in the case of[""]
it returns["", "", "", "", ""]
but it should remove this array.
– thedbogh
yesterday
Thank you, both yours and the Sid's solution work perfectly. Of course, I voted for both, but I can only accept one. I must choose in that case a solution with better performance. Which one do you think is better?
– thedbogh
yesterday
Yes, I updated the question. Thank you for your help.
– thedbogh
yesterday
I made a mistake. I didn't check a case when the longest array in the table is shorter than 5. Your solution works properly unfortunately Sid's is not. I accept your solution.
– thedbogh
yesterday
add a comment |
up vote
1
down vote
accepted
Let's break it down into steps:
- Find the max length in the arrays of the 2D array.
- Check if it's
>= 5
. Based on this, create amaxLength
. - Then loop through the 2D array, create the rest array and fill it with
""
. - Merge the rest array with each item of the 2D array.
Try this:
var initialTime = performance.now();
var array1 = [
["text1", "text2", "text3", "text4"],
["text5", "text6"],
["text7"],
["text8", "text9", "text10"],
[""]
];
var array2 = [
["text1", "text2", "text3", "text4"],
["text5", "text6"],
["text7"],
["text8", "text9", "text10", "text11", "text12", "text13"],
[""]
];
function fillRestItems(arrays) {
var maxArrayLength = Math
.max(...arrays.map(array => array.length));
var maxLength = maxArrayLength >= 5 ? maxArrayLength : 5;
return arrays
.map(arr => {
if(!(arr.length === 1 && arr[0] === "")) {
var addedArray = new Array(maxLength - arr.length).fill("");
return [...arr, ...addedArray];
}
})
.filter(array => array !== undefined);
}
console.log('Filled Array 1:', fillRestItems(array1));
console.log('Filled Array 2: ', fillRestItems(array2));
var finalTime = performance.now();
console.log(`This took: ${(finalTime - initialTime)} ms`);
This is almost what I wanted to achieve, however in the case of[""]
it returns["", "", "", "", ""]
but it should remove this array.
– thedbogh
yesterday
Thank you, both yours and the Sid's solution work perfectly. Of course, I voted for both, but I can only accept one. I must choose in that case a solution with better performance. Which one do you think is better?
– thedbogh
yesterday
Yes, I updated the question. Thank you for your help.
– thedbogh
yesterday
I made a mistake. I didn't check a case when the longest array in the table is shorter than 5. Your solution works properly unfortunately Sid's is not. I accept your solution.
– thedbogh
yesterday
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Let's break it down into steps:
- Find the max length in the arrays of the 2D array.
- Check if it's
>= 5
. Based on this, create amaxLength
. - Then loop through the 2D array, create the rest array and fill it with
""
. - Merge the rest array with each item of the 2D array.
Try this:
var initialTime = performance.now();
var array1 = [
["text1", "text2", "text3", "text4"],
["text5", "text6"],
["text7"],
["text8", "text9", "text10"],
[""]
];
var array2 = [
["text1", "text2", "text3", "text4"],
["text5", "text6"],
["text7"],
["text8", "text9", "text10", "text11", "text12", "text13"],
[""]
];
function fillRestItems(arrays) {
var maxArrayLength = Math
.max(...arrays.map(array => array.length));
var maxLength = maxArrayLength >= 5 ? maxArrayLength : 5;
return arrays
.map(arr => {
if(!(arr.length === 1 && arr[0] === "")) {
var addedArray = new Array(maxLength - arr.length).fill("");
return [...arr, ...addedArray];
}
})
.filter(array => array !== undefined);
}
console.log('Filled Array 1:', fillRestItems(array1));
console.log('Filled Array 2: ', fillRestItems(array2));
var finalTime = performance.now();
console.log(`This took: ${(finalTime - initialTime)} ms`);
Let's break it down into steps:
- Find the max length in the arrays of the 2D array.
- Check if it's
>= 5
. Based on this, create amaxLength
. - Then loop through the 2D array, create the rest array and fill it with
""
. - Merge the rest array with each item of the 2D array.
Try this:
var initialTime = performance.now();
var array1 = [
["text1", "text2", "text3", "text4"],
["text5", "text6"],
["text7"],
["text8", "text9", "text10"],
[""]
];
var array2 = [
["text1", "text2", "text3", "text4"],
["text5", "text6"],
["text7"],
["text8", "text9", "text10", "text11", "text12", "text13"],
[""]
];
function fillRestItems(arrays) {
var maxArrayLength = Math
.max(...arrays.map(array => array.length));
var maxLength = maxArrayLength >= 5 ? maxArrayLength : 5;
return arrays
.map(arr => {
if(!(arr.length === 1 && arr[0] === "")) {
var addedArray = new Array(maxLength - arr.length).fill("");
return [...arr, ...addedArray];
}
})
.filter(array => array !== undefined);
}
console.log('Filled Array 1:', fillRestItems(array1));
console.log('Filled Array 2: ', fillRestItems(array2));
var finalTime = performance.now();
console.log(`This took: ${(finalTime - initialTime)} ms`);
var initialTime = performance.now();
var array1 = [
["text1", "text2", "text3", "text4"],
["text5", "text6"],
["text7"],
["text8", "text9", "text10"],
[""]
];
var array2 = [
["text1", "text2", "text3", "text4"],
["text5", "text6"],
["text7"],
["text8", "text9", "text10", "text11", "text12", "text13"],
[""]
];
function fillRestItems(arrays) {
var maxArrayLength = Math
.max(...arrays.map(array => array.length));
var maxLength = maxArrayLength >= 5 ? maxArrayLength : 5;
return arrays
.map(arr => {
if(!(arr.length === 1 && arr[0] === "")) {
var addedArray = new Array(maxLength - arr.length).fill("");
return [...arr, ...addedArray];
}
})
.filter(array => array !== undefined);
}
console.log('Filled Array 1:', fillRestItems(array1));
console.log('Filled Array 2: ', fillRestItems(array2));
var finalTime = performance.now();
console.log(`This took: ${(finalTime - initialTime)} ms`);
var initialTime = performance.now();
var array1 = [
["text1", "text2", "text3", "text4"],
["text5", "text6"],
["text7"],
["text8", "text9", "text10"],
[""]
];
var array2 = [
["text1", "text2", "text3", "text4"],
["text5", "text6"],
["text7"],
["text8", "text9", "text10", "text11", "text12", "text13"],
[""]
];
function fillRestItems(arrays) {
var maxArrayLength = Math
.max(...arrays.map(array => array.length));
var maxLength = maxArrayLength >= 5 ? maxArrayLength : 5;
return arrays
.map(arr => {
if(!(arr.length === 1 && arr[0] === "")) {
var addedArray = new Array(maxLength - arr.length).fill("");
return [...arr, ...addedArray];
}
})
.filter(array => array !== undefined);
}
console.log('Filled Array 1:', fillRestItems(array1));
console.log('Filled Array 2: ', fillRestItems(array2));
var finalTime = performance.now();
console.log(`This took: ${(finalTime - initialTime)} ms`);
edited yesterday
answered yesterday
SiddAjmera
8,99121037
8,99121037
This is almost what I wanted to achieve, however in the case of[""]
it returns["", "", "", "", ""]
but it should remove this array.
– thedbogh
yesterday
Thank you, both yours and the Sid's solution work perfectly. Of course, I voted for both, but I can only accept one. I must choose in that case a solution with better performance. Which one do you think is better?
– thedbogh
yesterday
Yes, I updated the question. Thank you for your help.
– thedbogh
yesterday
I made a mistake. I didn't check a case when the longest array in the table is shorter than 5. Your solution works properly unfortunately Sid's is not. I accept your solution.
– thedbogh
yesterday
add a comment |
This is almost what I wanted to achieve, however in the case of[""]
it returns["", "", "", "", ""]
but it should remove this array.
– thedbogh
yesterday
Thank you, both yours and the Sid's solution work perfectly. Of course, I voted for both, but I can only accept one. I must choose in that case a solution with better performance. Which one do you think is better?
– thedbogh
yesterday
Yes, I updated the question. Thank you for your help.
– thedbogh
yesterday
I made a mistake. I didn't check a case when the longest array in the table is shorter than 5. Your solution works properly unfortunately Sid's is not. I accept your solution.
– thedbogh
yesterday
This is almost what I wanted to achieve, however in the case of
[""]
it returns ["", "", "", "", ""]
but it should remove this array.– thedbogh
yesterday
This is almost what I wanted to achieve, however in the case of
[""]
it returns ["", "", "", "", ""]
but it should remove this array.– thedbogh
yesterday
Thank you, both yours and the Sid's solution work perfectly. Of course, I voted for both, but I can only accept one. I must choose in that case a solution with better performance. Which one do you think is better?
– thedbogh
yesterday
Thank you, both yours and the Sid's solution work perfectly. Of course, I voted for both, but I can only accept one. I must choose in that case a solution with better performance. Which one do you think is better?
– thedbogh
yesterday
Yes, I updated the question. Thank you for your help.
– thedbogh
yesterday
Yes, I updated the question. Thank you for your help.
– thedbogh
yesterday
I made a mistake. I didn't check a case when the longest array in the table is shorter than 5. Your solution works properly unfortunately Sid's is not. I accept your solution.
– thedbogh
yesterday
I made a mistake. I didn't check a case when the longest array in the table is shorter than 5. Your solution works properly unfortunately Sid's is not. I accept your solution.
– thedbogh
yesterday
add a comment |
up vote
1
down vote
First step would be to find the sub-array of maximum size.
let arr = [["text1", "text2", "text3", "text4"],
["text5", "text6"],
["text7"],
["text8", "text9", "text10"],
[""]];
arr = arr.filter(e => e.every(x => x !== ""))
const maxLength = Math.max(...arr.map(a => a.length));
The next step is to fill the array with blank values.
arr.forEach(e => {
while(e.length < maxLength){
e.push("");
}
});
console.log(arr);
I am sure there are better ways of doing it as the time complexity of the algorithm is O(n2)
This is almost what I wanted to achieve, however in the case of[""]
it returns["", "", "", "", ""]
but it should remove this array.
– thedbogh
yesterday
Fixed the code to filter unwanted items.
– Sid
yesterday
Thank you, both yours and the SiddAjmera's solution work perfectly. Of course, I voted for both, but I can only accept one. I must choose in that case a solution with better performance. Which one do you think is better?
– thedbogh
yesterday
Go with whoever answered first . ;)
– Sid
yesterday
I made a mistake. I didn't check a case when the longest array in the table is shorter than 5. In your case it doesn't work. Performance in both cases is similar so in accordance to your suggestion I accept the solution of SiddAjmera.
– thedbogh
yesterday
add a comment |
up vote
1
down vote
First step would be to find the sub-array of maximum size.
let arr = [["text1", "text2", "text3", "text4"],
["text5", "text6"],
["text7"],
["text8", "text9", "text10"],
[""]];
arr = arr.filter(e => e.every(x => x !== ""))
const maxLength = Math.max(...arr.map(a => a.length));
The next step is to fill the array with blank values.
arr.forEach(e => {
while(e.length < maxLength){
e.push("");
}
});
console.log(arr);
I am sure there are better ways of doing it as the time complexity of the algorithm is O(n2)
This is almost what I wanted to achieve, however in the case of[""]
it returns["", "", "", "", ""]
but it should remove this array.
– thedbogh
yesterday
Fixed the code to filter unwanted items.
– Sid
yesterday
Thank you, both yours and the SiddAjmera's solution work perfectly. Of course, I voted for both, but I can only accept one. I must choose in that case a solution with better performance. Which one do you think is better?
– thedbogh
yesterday
Go with whoever answered first . ;)
– Sid
yesterday
I made a mistake. I didn't check a case when the longest array in the table is shorter than 5. In your case it doesn't work. Performance in both cases is similar so in accordance to your suggestion I accept the solution of SiddAjmera.
– thedbogh
yesterday
add a comment |
up vote
1
down vote
up vote
1
down vote
First step would be to find the sub-array of maximum size.
let arr = [["text1", "text2", "text3", "text4"],
["text5", "text6"],
["text7"],
["text8", "text9", "text10"],
[""]];
arr = arr.filter(e => e.every(x => x !== ""))
const maxLength = Math.max(...arr.map(a => a.length));
The next step is to fill the array with blank values.
arr.forEach(e => {
while(e.length < maxLength){
e.push("");
}
});
console.log(arr);
I am sure there are better ways of doing it as the time complexity of the algorithm is O(n2)
First step would be to find the sub-array of maximum size.
let arr = [["text1", "text2", "text3", "text4"],
["text5", "text6"],
["text7"],
["text8", "text9", "text10"],
[""]];
arr = arr.filter(e => e.every(x => x !== ""))
const maxLength = Math.max(...arr.map(a => a.length));
The next step is to fill the array with blank values.
arr.forEach(e => {
while(e.length < maxLength){
e.push("");
}
});
console.log(arr);
I am sure there are better ways of doing it as the time complexity of the algorithm is O(n2)
edited yesterday
answered yesterday
Sid
2,863103580
2,863103580
This is almost what I wanted to achieve, however in the case of[""]
it returns["", "", "", "", ""]
but it should remove this array.
– thedbogh
yesterday
Fixed the code to filter unwanted items.
– Sid
yesterday
Thank you, both yours and the SiddAjmera's solution work perfectly. Of course, I voted for both, but I can only accept one. I must choose in that case a solution with better performance. Which one do you think is better?
– thedbogh
yesterday
Go with whoever answered first . ;)
– Sid
yesterday
I made a mistake. I didn't check a case when the longest array in the table is shorter than 5. In your case it doesn't work. Performance in both cases is similar so in accordance to your suggestion I accept the solution of SiddAjmera.
– thedbogh
yesterday
add a comment |
This is almost what I wanted to achieve, however in the case of[""]
it returns["", "", "", "", ""]
but it should remove this array.
– thedbogh
yesterday
Fixed the code to filter unwanted items.
– Sid
yesterday
Thank you, both yours and the SiddAjmera's solution work perfectly. Of course, I voted for both, but I can only accept one. I must choose in that case a solution with better performance. Which one do you think is better?
– thedbogh
yesterday
Go with whoever answered first . ;)
– Sid
yesterday
I made a mistake. I didn't check a case when the longest array in the table is shorter than 5. In your case it doesn't work. Performance in both cases is similar so in accordance to your suggestion I accept the solution of SiddAjmera.
– thedbogh
yesterday
This is almost what I wanted to achieve, however in the case of
[""]
it returns ["", "", "", "", ""]
but it should remove this array.– thedbogh
yesterday
This is almost what I wanted to achieve, however in the case of
[""]
it returns ["", "", "", "", ""]
but it should remove this array.– thedbogh
yesterday
Fixed the code to filter unwanted items.
– Sid
yesterday
Fixed the code to filter unwanted items.
– Sid
yesterday
Thank you, both yours and the SiddAjmera's solution work perfectly. Of course, I voted for both, but I can only accept one. I must choose in that case a solution with better performance. Which one do you think is better?
– thedbogh
yesterday
Thank you, both yours and the SiddAjmera's solution work perfectly. Of course, I voted for both, but I can only accept one. I must choose in that case a solution with better performance. Which one do you think is better?
– thedbogh
yesterday
Go with whoever answered first . ;)
– Sid
yesterday
Go with whoever answered first . ;)
– Sid
yesterday
I made a mistake. I didn't check a case when the longest array in the table is shorter than 5. In your case it doesn't work. Performance in both cases is similar so in accordance to your suggestion I accept the solution of SiddAjmera.
– thedbogh
yesterday
I made a mistake. I didn't check a case when the longest array in the table is shorter than 5. In your case it doesn't work. Performance in both cases is similar so in accordance to your suggestion I accept the solution of SiddAjmera.
– thedbogh
yesterday
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237873%2fhow-can-i-change-the-length-of-each-table-to-be-equal-to-the-longest-one-provide%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password