javascript - Efficient CSV Row Reduction JS -


i have huge csv i'm trying filter based on user input. looks this:

from,phone_number,from_date seattle,123,6/15/15 omaha,321,6/14/15 

i have function supposed take user input , match rows meet criteria.

var lst = [] var lst2 = [] var lst3 = []  function mapper() { var dateu = document.getelementbyid("userinputdate").value; var cityu = document.getelementbyid("userinputcity").value; var numberu = document.getelementbyid("userinputnumber").value;  d3.csv("some.csv", function(d) {   return {     city: d.from,     number: d.phone_number,     date: d.from_date   }; }, function(error, rows) { (var = 0; < rows.length; i++) {     lst.push(rows); if (dateu.length > 0) {     (var = 0; < lst.length; i++) {         if (lst[i].date === dateu) {             lst.push(rows[i]);             console.log(rows[i]);         }     }     if (cityu.length > 0) {         (var = 0; < lst.length; i++) {             if (lst[i].city === cityu) {                 lst2.push(lst[i]);                 console.log(lst2);             }         }         if (numberu.length > 0) {             (var = 0; < lst2.length; i++) {                 if (lst[i].number === numberu) {                     lst3.push(lst2[i]);                     console.log(lst3);                 }             }         }     } } }})}; 

the matching , passing works, the problem user doesn't have enter fields. example might input data "city_u" variable , unfortunately city matching (second if statement) relies on array previous if statement.

im looking way each if statement filtered version of data can receive. second , third if statements run regardless of whether or not previous ones have.

oh forgot mention, need able write final array csv. importantly not going hosted online immediately. csv should write same folder files in.

i can see want filter based on these 3 variables ,, maybe function helps you

function apply_filters(data, dateu,cityu,numberu){     if(dateu) {          data = data.filter(function(item){return item.date == dateu;});     };     if(cityu){         data = data.filter(function(item){return item.city == cityu;});     }      if(numberu){         data = data.filter(function(item){return item.number == numberu;});     }     return data; } 

so need pass data array , 3 filters params can read filter function here : https://developer.mozilla.org/en/docs/web/javascript/reference/global_objects/array/filter


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -