I am currently working with two arrays that can be of equal length or one may be longer than the other.
My goal is to determine the longest array if they are not equal in length, and then use this length to control a loop.
$.ajax({
url: "/static/Data/q_learning.json",
dataType: "json",
cache: false,
async: true,
success: function (data) {
var data2 = data;
$.ajax({
url: "/static/Data/sarsa.json",
dataType: "json",
cache: false,
async: true,
success: function (data1) {
var data1 = data1;
var json_data = data2;
var json_data1 = data1;
json_data = json_data[Object.keys(data2)[0]];
json_data1 = json_data1[Object.keys(data1)[0]];
var result = [];
var biggest = [];
switch (json_data) {
case json_data.length > json_data1.length:
biggest = json_data;
break;
case json_data.length < json_data1.length:
biggest = json_data1;
break;
case json_data1.length > json_data.length:
biggest = json_data1;
break;
case json_data1.length < json_data.length:
biggest = json_data;
break;
default:
biggest = json_data1;
}
console.log(biggest);
for (var i in biggest)
result.push([i, json_data[i], json_data1[i]]);
console.log(result);
To determine the longest array, I compare their lengths and assign the larger one to a temporary array called "biggest."
If the arrays are of equal length, it doesn't matter which one is assigned as they both have the same length.
While this logic works sometimes, I am facing an issue where the longest array is not always correctly being assigned to the "biggest" temporary array. https://i.sstatic.net/mOrD1.png
The graph above illustrates the two sets of data on the same timeline, with one set being longer than the other.
When I adjust one variable higher than the other, the graph changes to reflect this difference. However, setting the other variable higher results in them being equal, as shown in the image below. https://i.sstatic.net/GwrNM.png I feel like the solution is right in front of me, but I can't seem to figure it out.
I would greatly appreciate any assistance or suggestions. Thank you!