Skip to content
Astera Technology

Extract a cell’s complete merged-header path

Leaf headings repeat and lose their parent column group.

Download complete case notes and answer keys ↓

Define the local evaluation task

A synthetic dispatch sheet has two parent headings, requested and delivered, each with a leaf heading units. Column paths and row values are explicit ordered arrays. Produce path/value entries with the full two-level path of exactly two nonempty text components; repeated full paths or different array lengths invalidate the row. Zero remains an observed value.

  1. Read parent and leaf together
  2. Check one value for every distinct full path
  3. Emit complete path/value pairs

Ambiguous or missing paths require document-layout review.

Use the filled cases

Original synthetic input and literal answer key
CaseSupplied inputExpected structured outputDecision and reason
Same leaf under different parents{"paths":[["requested","units"],["delivered","units"]],"values":[8,5]}{"fields":[{"path":["requested","units"],"value":8},{"path":["delivered","units"],"value":5}]}Requested eight and delivered five retain distinct parent paths.
Delivered zero observed{"paths":[["requested","units"],["delivered","units"]],"values":[4,0]}{"fields":[{"path":["requested","units"],"value":4},{"path":["delivered","units"],"value":0}]}The zero stays attached to delivered.units, not to a missing field.
Leaf heading lacks parent{"paths":[["units"]],"values":[8]}{"error":"header-association"}Units alone is not the required two-level parent/leaf association.
Full path repeated{"paths":[["requested","units"],["requested","units"]],"values":[8,5]}{"error":"header-association"}Two values claim one full field; do not silently overwrite either.
Download editable CSV ↓

Work the duplicate-path case. Which output is required, and why?

Show the worked answer

{"error":"header-association"} — Two values claim one full field; do not silently overwrite either.

Run the self-contained evaluator

Save as .mjs and run with Node.js; supplied fixtures only
import assert from 'node:assert/strict';

function evaluate(x){
 if(x.paths.some(path=>!Array.isArray(path)||path.length!==2||path.some(part=>typeof part!=='string'||!part.trim())))return {error:'header-association'};
 const keys=x.paths.map(p=>JSON.stringify(p));
 if(x.paths.length!==x.values.length||new Set(keys).size!==keys.length)return {error:'header-association'};
 return {fields:x.paths.map((path,i)=>({path,value:x.values[i]}))};
}

const cases = [
  {
    "id": "same-leaf",
    "input": {
      "paths": [
        [
          "requested",
          "units"
        ],
        [
          "delivered",
          "units"
        ]
      ],
      "values": [
        8,
        5
      ]
    },
    "expected": {
      "fields": [
        {
          "path": [
            "requested",
            "units"
          ],
          "value": 8
        },
        {
          "path": [
            "delivered",
            "units"
          ],
          "value": 5
        }
      ]
    }
  },
  {
    "id": "observed-zero",
    "input": {
      "paths": [
        [
          "requested",
          "units"
        ],
        [
          "delivered",
          "units"
        ]
      ],
      "values": [
        4,
        0
      ]
    },
    "expected": {
      "fields": [
        {
          "path": [
            "requested",
            "units"
          ],
          "value": 4
        },
        {
          "path": [
            "delivered",
            "units"
          ],
          "value": 0
        }
      ]
    }
  },
  {
    "id": "leaf-without-parent",
    "input": {
      "paths": [
        [
          "units"
        ]
      ],
      "values": [
        8
      ]
    },
    "expected": {
      "error": "header-association"
    }
  },
  {
    "id": "duplicate-path",
    "input": {
      "paths": [
        [
          "requested",
          "units"
        ],
        [
          "requested",
          "units"
        ]
      ],
      "values": [
        8,
        5
      ]
    },
    "expected": {
      "error": "header-association"
    }
  }
];
for (const c of cases) assert.deepEqual(evaluate(c.input), c.expected, c.id);
console.log(JSON.stringify({checked:cases.length,caseIds:cases.map(c=>c.id)}));
Download runnable example ↓

Keep the observed layout association beside the extracted row. This dataset tests grouped headings, without claiming to run OCR or to verify quantities against physical stock.

Related resources

Workflow automation services →