DEV Community

hditano
hditano

Posted on

Matching two Values from an Array (CSV) and an Axios Request and if so.. print out proper value (third value)

I'm still learning Javascript. so this is what i came with. Which obviously its not working as expected.

const ESI = axios.get('https://esi.evetech.net/latest/markets/10000002/orders/?datasource=tranquility&order_type=all&page=1')
.then(function (response) {
  console.log(response.data);
  for(let i of response.data){
    console.log(i.type_id);
  }
}) 

function doStuff(data) {
  //Data is usable here
  console.log(data);
}

function parseData(url, callBack) {
  Papa.parse(url, {
      download: true,
      dynamicTyping: true,
      complete: function(results) { 
          callBack(results.data);
      }
  });
}

const csvData = parseData("invTypes.csv", doStuff);

console.log(csvData);

Array.prototype.diff = function(csvData) {
  var ret = [];
  this.sort();
  csvData.sort();
  for( var i = 0; i < this.length; i += 1) {
    if(csvData.indexOf(this[i] > -1) > -1) {
      ret.push(this[i]);
    }
  }
  return ret;
}

console.log(ESI.diff(csvData));

I am trying to do the following.
Axios returns the results in the following format.

0:
duration: 90
is_buy_order: false
issued: "2020-04-26T13:09:52Z"
location_id: 60003760
min_volume: 1
order_id: 5672796166
price: 99890
range: "region"
system_id: 30000142
type_id: 33092
volume_remain: 25
volume_total: 28

This is what i get from PapaParse (its around 35.000 csv lines parsed).

18941: Array(15)
0: 33092
1: 257
2: "Caldari Destroyer"
3: "Skill at operating Caldari destroyers."
4: "0E-10"
5: 0.01
6: "0E-10"
7: 1
8: 1
9: 100000
10: 1
11: 377
12: 33
13: "None"
14: 0

As you can see Type_ID and 0: Matches since they are both the same ID : 33092. If so..i need to return the value of the 2: which in this case is Caldari Destroyer.

Not quite sure what would be a better way to handle this?? MongoDB? MySql?
If so..what should i look for?

Top comments (0)