const splitFeatures = function()

in scripts/layerdiff.js [212:270]


const splitFeatures = function (leftJson, rightJson) {
  let features = [];
  const notLeft = [];

  if (CHECK_ID) {
    // Find the elements directly  by the provided ID
    const id = CHECK_ID;
    const left = leftJson.features.find(f => getId(f) === id);
    const right = rightJson.features.find(f => getId(f) === id);

    if (left && right) {
      features.push({ id, left, right });
    } else {
      if (!left) {
        print('❌ ID not found in the left GeoJSON');
      }
      if (!right) {
        print('❌ ID not found in the right GeoJSON');
      }
      yargs.exit(0);
    }
  } else {
    // Join the two arrays merging by the id

    // Put all the left features in a new object
    features = leftJson.features.map(f => {
      const id = getId(f);
      return {
        id,
        left: f,
      };
    });

    // Put all the right features in the main object
    // and save the ones that are not found for later
    rightJson.features.forEach(f => {
      const id = getId(f);
      const fIndex = features.findIndex(ff => ff.id === id);
      if (fIndex === -1) {
        notLeft.push(f);
      } else {
        features[fIndex].right = f;
      }
    });
  }

  // Find if there are any features from the left
  // without the right side
  const notRight = features.filter(f => !('right' in f));

  // Work only with features that are on both sides
  const finalFeatures = features.filter(f => 'right' in f);

  return {
    notLeft,
    notRight,
    features: finalFeatures,
  };
};