I have a set of data that has been organized into an array format. My goal is to retain the original dataset while creating a modified array as output within a function. This modified array will then be used in subsequent functions to visualize graph data.
The initial array of data looks like this:
dataArray = [
['Day', '1', '2', '3', '4', '5', '6'],
['Day -7',0,0,0,0,0,0,],
['Day -6',0,0,0,0,0,0,],
['Day -5',0,0,0,0,0,0,],
['Day -4',0,0,0,0,0,0,],
['Day -3',0,0,0,0,0,0,],
['Day -2',0,0,0,0,0,0,],
];
In addition, I have created an array called switch
:
switch = [];
switch[0] = false;
switch[1] = false;
switch[2] = false;
switch[3] = false;
switch[4] = false;
switch[5] = false;
switch[6] = false;
Within my code, my objective is to iterate through the length of the switch
array and remove the corresponding column or index from each line in the dataArray
array.
function workingDataArray(){
workingArray = null;
workingArray = dataArray.slice();
var switchLength = switch.length;
for (var i = 0; i < switchLength; i++) {
if(!switch[i]){
// Code to remove items at this position if the switch is true
}
}
return workingArray;
}
The concept here is that by setting switch[3]
and switch[5]
to true
, the output will be:
['Day', '1', '2', '4', '6']
['Day -7',0,0,0,0,]
['Day -6',0,0,0,0,]
['Day -5',0,0,0,0,]
['Day -4',0,0,0,0,]
['Day -3',0,0,0,0,]
['Day -2',0,0,0,0,]
This approach makes sense to me, but I am open to suggestions on how to improve it and welcome any guidance in the right direction.