Array of string, compare values of first and last parametres of strings

92 views Asked by At

Tnx for answer. My problem is that i have csv file with lines that i wrote down. I need to submit all numbers in first column (i need to submit just lines with the same text at the end) . After i need to find lenght of lines with the same text(for example, here is 4 of "Sanja", 2 of "Ana" ), after it i need max, average and min number from first column of "Sanja" lines, and max, min and average number from second column, of "Sanja" lines. And to do the same for every different text! But it will be easy if i find out how to do that with one! So, i have csv file as table with more then 100 lines. At the end, i need to put all that informatiom in table, which i need to save and send as table.txt. I need to use JavaScript for this problem. Csv:

5.2   4.5   7.5   Sanja
1.3   2.7   6.4   Sanja
1.2   4.3   5.5   Ana
5.4   4.5   7.5   Sanja
6.3   2.7   6.4   Sanja
1.2   4.3   5.9   Ana

Etc I need to do ajax call, which will give me array of strings separated by each line in file? And what after?

1

There are 1 answers

0
Martin On

How about simply iterating each string in your array and splitting that into an array that you push onto your result.

It would effectively be an array of arrays, as seen in the following snippet:

var Arr = [
"2.3,5.2,4.4,Sanja",
"5.3,5.7,3.4,Sanja",
"2.3,5.2,4.4,Ana",
]

var result = [];

Arr.forEach(function(i) {
  result.push(i.split(','));
});

console.dir(result);

Outputs:

[
  [
    "2.3",
    "5.2",
    "4.4",
    "Sanja"
  ],
  [
    "5.3",
    "5.7",
    "3.4",
    "Sanja"
  ],
  [
    "2.3",
    "5.2",
    "4.4",
    "Ana"
  ]
]

Why Not Objects

You can't make an object from 2.3,5.2,4.4,Sanja because this is not representative of a valid object. My example shows these as an array which may not be what you are looking for.