'use strict';
var turf = require('turf');
var preserveType = {
  'motorway': true,
  'primary': true,
  'secondary': true,
  'tertiary': true,
  'trunk': true,
  'residential': true,
  'unclassified': true
};

module.exports = function(tileLayers, tile, writeData, done) {
  var osm = tileLayers.osm.osm;
  var tiger = tileLayers.tiger.tiger2015;
  var osmFC = osm.features.filter(function(val) {
    return val.properties.highway && (val.geometry.type === 'LineString') && preserveType[val.properties.highway] && !val.properties.name && !val.properties.ref;
  });
  var tigerFC = tiger.features.filter(function(val) {
    return val.properties.FULLNAME && (val.geometry.type === 'LineString');
  });
  var result = [];
  if (osmFC.length > 0) {
    osmFC.forEach(function(way) {
      var buffer = turf.buffer(way, 0.004, 'miles');
      tigerFC.forEach(function(line) {
        var tigerPoints = turf.explode(line);
        var nodes;
        nodes = turf.within(tigerPoints, buffer);
        if (nodes.features.length >= (tigerPoints.features.length / 2) && line.properties.FULLNAME) {
          way.properties._osmlint = 'missinghighwayus';
          way.properties.name = line.properties.FULLNAME;
          result.push(way);
        }
      });
    });
  }

  if (result.length > 0) {
    var fc = turf.featurecollection(result);
    writeData(JSON.stringify(fc) + '\n');
  }

  done(null, null);
};

'use strict';
var turf = require('turf');

module.exports = function(tileLayers, tile, writeData, done) {
  var osmLayer = tileLayers.osm.osm;
  var tigerLayer = tileLayers.tiger.tiger2015;
  var preserveType = {
    'motorway': true,
    'motorway_link': true,
    'primary': true,
    'primary_link': true,
    'secondary': true,
    'secondary_link': true,
    'tertiary': true,
    'tertiary_link': true,
    'trunk': true,
    'trunk_link': true,
    'residential': true,
    'unclassified': true,
    'living_street': true,
    'road': true
  };
  var osmlint = 'missinghighwayus';
  var osmFC = [];
  var tigerFC = [];

  for (var k = 0; k < osmLayer.features.length; k++) {
    var osmVal = osmLayer.features[k];
    if (osmVal.properties.highway && (osmVal.geometry.type === 'LineString') && preserveType[osmVal.properties.highway] && !osmVal.properties.name && !osmVal.properties.ref) {
      osmFC.push(osmVal);
    }
  }
  for (var h = 0; h < tigerLayer.features.length; h++) {
    var tigerVal = tigerLayer.features[h];
    if (tigerVal.properties.FULLNAME && (tigerVal.geometry.type === 'LineString')) {
      tigerFC.push(tigerVal);
    }
  }

  var result = [];

  if (osmFC.length > 0) {
    for (var i = 0; i < osmFC.length; i++) {
      var osmWay = osmFC[i];
      var buffer = turf.buffer(osmWay, 0.004, 'miles');
      for (var j = 0; j < tigerFC.length; j++) {
        var tigerWay = tigerFC[j];
        var tigerPoints = turf.explode(tigerWay);
        var nodes;
        nodes = turf.within(tigerPoints, buffer);
        if (nodes.features.length >= (tigerPoints.features.length / 2) && tigerWay.properties.FULLNAME) {
          osmWay.properties._osmlint = osmlint;
          osmWay.properties.name = tigerWay.properties.FULLNAME;
          result.push(osmWay);
        }
      }
    }
  }

  if (result.length > 0) {
    var fc = turf.featurecollection(result);
    writeData(JSON.stringify(fc) + '\n');
  }

  done(null, null);
};

change forEach by for loop