hhzl / LearnWords2

A word learning component (Leitner system) and word list conversion functions
MIT License
11 stars 2 forks source link

Extract duplicate code in Gruntfile.js #171

Closed hhzl closed 7 years ago

hhzl commented 7 years ago
var result = Papa.parse(data,{
          dynamicTyping: true,
          encoding: 'utf8',
          skipEmptyLines: true
        });

       if(result.errors.length == 0){
          // result.data is array of arrays
          // row with index 0 is header

          var arrayOfObjects = [];
          var propertyName;
          for(var j = 1; j < result.data.length; j++){
            var obj = {};
            for(var k = 0; k < result.data[0].length; k++){
              if(k < result.data[j].length){
                propertyName = result.data[0][k];
                obj[propertyName] = result.data[j][k];
              }
            }
            arrayOfObjects.push(obj);
          }