Read the source and its declared rule
The original extracted merge spans column 1, rows 2..3 inclusive, with North at its top-left anchor. Only covered missing cells inherit that anchor in this fixture. The supplied ranges are valid and nonoverlapping; ordinary blank cells outside the range remain null.
| Record | Input JSON |
|---|---|
| Base input | {"column":1,"rows":[2,3,4],"cells":[{"row":2,"col":1,"value":"North"}],"merges":[{"fromRow":2,"toRow":3,"fromCol":1,"toCol":1}]} |
Compare the actual paths
Correct output fills row 3 but leaves row 4 null. The algorithm checks coordinate membership, not merely whether a previous nonblank heading exists.
| Path | Output JSON |
|---|---|
| Misleading path | [{"row":2,"value":"North"},{"row":3,"value":"North"},{"row":4,"value":"North"}] |
| Corrected path | [{"row":2,"value":"North"},{"row":3,"value":"North"},{"row":4,"value":null}] |
import {DatabaseSync} from 'node:sqlite';
import {TextDecoder} from 'node:util';
import {inflateSync} from 'node:zlib';
import {posix} from 'node:path';
import {createHash} from 'node:crypto';
const rows=(db,sql)=>db.prepare(sql).all().map(r=>({...r}));
const failed=(action)=>{try{action();return null;}catch(e){return {code:e.errcode??e.code??e.name};}};
import assert from 'node:assert/strict';
const run=function run(i,corrected=true){
const output=[];let carried=null;
for(const row of i.rows){
const own=i.cells.find(c=>c.row===row&&c.col===i.column);
if(own)carried=own.value;
if(!corrected){output.push({row,value:carried});continue;}
const merge=i.merges.find(m=>row>=m.fromRow&&row<=m.toRow&&i.column>=m.fromCol&&i.column<=m.toCol);
const anchor=merge?i.cells.find(c=>c.row===merge.fromRow&&c.col===merge.fromCol):null;
output.push({row,value:own?own.value:anchor?anchor.value:null});
}return output;
};
const cases=[{"label":"misleading base","input":{"column":1,"rows":[2,3,4],"cells":[{"row":2,"col":1,"value":"North"}],"merges":[{"fromRow":2,"toRow":3,"fromCol":1,"toCol":1}]},"expected":[{"row":2,"value":"North"},{"row":3,"value":"North"},{"row":4,"value":"North"}],"corrected":false},{"label":"corrected base","input":{"column":1,"rows":[2,3,4],"cells":[{"row":2,"col":1,"value":"North"}],"merges":[{"fromRow":2,"toRow":3,"fromCol":1,"toCol":1}]},"expected":[{"row":2,"value":"North"},{"row":3,"value":"North"},{"row":4,"value":null}],"corrected":true},{"label":"column outside merge","input":{"column":2,"rows":[2,3],"cells":[{"row":2,"col":1,"value":"North"}],"merges":[{"fromRow":2,"toRow":3,"fromCol":1,"toCol":1}]},"expected":[{"row":2,"value":null},{"row":3,"value":null}],"corrected":true},{"label":"no merged range","input":{"column":1,"rows":[2,3],"cells":[{"row":2,"col":1,"value":"North"}],"merges":[]},"expected":[{"row":2,"value":"North"},{"row":3,"value":null}],"corrected":true}];
for(const test of cases){
const actual=run(test.input,test.corrected);
assert.deepEqual(actual,test.expected,test.label);
console.log(test.label,actual);
}
Check boundaries before the next load
Column 2 is outside the merge and remains blank. Without any merge, row 3 does not inherit North.
| Case | Input JSON | Expected output JSON |
|---|---|---|
| Column outside the merge | {"column":2,"rows":[2,3],"cells":[{"row":2,"col":1,"value":"North"}],"merges":[{"fromRow":2,"toRow":3,"fromCol":1,"toCol":1}]} | [{"row":2,"value":null},{"row":3,"value":null}] |
| No declared merge | {"column":1,"rows":[2,3],"cells":[{"row":2,"col":1,"value":"North"}],"merges":[]} | [{"row":2,"value":"North"},{"row":3,"value":null}] |
Should North reach row 4?
Show the worked answer
No. Row 4 is beyond the inclusive 2..3 merge. Only rows 2 and 3 contain North in column 1.