0

I have 2 api calls, and they both push values into a multidimensional array, in order to associate the corresponding value results from the api calls.

When I run the following:

console.log(JSON.stringify(spacetime), null, "\t");

The console gives me:

[
  {
    "Title":
      [
        "Battle of Baekgang","Victory Tests","Everett massacre"
      ],
    "Space": [
      "United States"
    ],
    "Time": [
      "27 - 28 August 663 CE ",
      "27 - 28 August 663 CE 19 May 1945 – 22 August 1945 ",
      "27 - 28 August 663 CE 19 May 1945 – 22 August 1945 November 5, 1916 "
    ]
  }
]

But the values don't match, I have 3 objects with Title, one with Space and 3 with Time

This is the jsFiddle, it is a bit long so a bit of quick guide:

  1. On line 69 we run the first set of calls with wikiText(), 500, they need to be this much otherwise we wouldn't find results matching the criteria. And we push the current title and the current date like this:

      spacetime[0].Title.push(curTitle);
      spacetime[0].Time.push(d);
    
  2. On this call we do a lot of checks, but we want to concentrate on the lines 108 - 128 - 149 and 169, basically these are the lines that run the second api call: countryPage();

On the second api call, we check if the current page has any other matching criteria, and if so we push the result into the multi dimensional array called Space[].

This last push tho, it is related to the call we did when doing one of the else on wikiText() meaning we didn't find space so we launch countryPage(); to find it.

But the relations don't happen, they get pushed but not in the correct order nor the correct number of items as per the first part above of this question. It is driving me nuts for 2 days tbh.

Roberto Marras
  • 153
  • 2
  • 11
  • Try to log the info before you push it to the arrays. Maybe the info is not arriving correctly and therefore you are not seeing it in the result – alexhenkel Jul 30 '17 at 18:57
  • @alexhenkel I have tried soo many different ways, this is the last try when there is missing info but before there was a mismatch with space and time and the title. Really can't get my head around it:( – Roberto Marras Jul 30 '17 at 18:58
  • @RobertoMarras The code at linked jsfiddle https://jsfiddle.net/jikupin/pz3ce0o6/589/ at present Question appears to be the substantially the same code at linked jsfiddle https://jsfiddle.net/jikupin/pz3ce0o6/411/ at this Question [How to define total length of a function(data)?](https://stackoverflow.com/q/45395938/). Why do you not include all relevant details of your inquiry at a single Question? – guest271314 Jul 30 '17 at 19:18
  • @guest271314 because I am trying to do it and work it out myself bit by bit and ask the single questions when I need to, also because this way I will learn. For example now I am stack here, can you help? https://pastebin.com/yeMwjvsr – Roberto Marras Jul 30 '17 at 19:32
  • Using `$.when()` , `.apply()` or `.queue()` and `.promise()` should return expected result, as suggested at other Question – guest271314 Jul 30 '17 at 19:34
  • @guest271314 check the chat – Roberto Marras Jul 30 '17 at 19:35

0 Answers0