index.js
// This function filters out unused keys and combines the datasets together
This function filters out unused keys and combines the datasets together
This function filters out unused keys and combines the datasets together
function filterData(data, keys) {
  let combinedData = [];
  data.forEach(dataset => {
    dataset.forEach(obj => {
      let cleanedObj = {};
      const objInArray = combinedData.find(x => x.areaid === obj.areaid); 
      if (objInArray) {
        cleanedObj = objInArray;
      }
      keys.forEach(key => {
        if (Object.prototype.hasOwnProperty.call(obj, key)) {
          cleanedObj[key] = obj[key];
        }
      });
      combinedData = combinedData.filter(x => x.areaid !== obj.areaid);
      combinedData.push(cleanedObj);
    })
  });
  return combinedData;
}
function filterData ( data , keys ) { let combinedData = [ ] ; data . forEach ( dataset => { dataset . forEach ( obj => { let cleanedObj = { } ; const objInArray = combinedData . find ( x => x . areaid === obj . areaid ) ; if ( objInArray ) { cleanedObj = objInArray ; } keys . forEach ( key => { if ( Object . prototype . hasOwnProperty . call ( obj , key ) ) { cleanedObj [ key ] = obj [ key ] ; } } ) ; combinedData = combinedData . filter ( x => x . areaid !== obj . areaid ) ; combinedData . push ( cleanedObj ) ; } ) } ) ; return combinedData ; }
This function filters out unused keys and combines the datasets together
This function filters out unused keys and combines the datasets together
// Find shared areaids and puts them in a variable // areaid is already in, just add missing key/values // Sets the keys that we need in our dataset // object has key, set it