跳至內容
Astera Technology

按指定終止鍵分清每次掃描

完整掃描與未完尾段分開留,不估中間界線。

下載完整個案資料及參考答案 ↓

訂判斷及所需輸入

本例 ENTER 結束一次輸入,所需代碼三字。A12 ENTER B34 ENTER 是兩段;全拼字會丟界線,成 A12B34。若合字後才得一次 ENTER,就是一段超長輸入待查,不是已證實兩次掃描。

已填本地測試工作表
情況輸入 JSON
原例測試{"keys":["A","1","2","ENTER","B","3","4","ENTER"]}
下載可編輯 CSV ↓

跑所附比較

狀態程序只在指定終止鍵結段。分段收件與查清單不同,收到字不會自動建庫存移動。

錯誤及所需輸出
路徑輸出 JSON
錯誤路徑{"frames":["A12B34"],"pending":"","requiresReview":false}
所需路徑{"frames":["A12","B34"],"pending":"","requiresReview":false}
下載可編輯 CSV ↓
完整本地 Node24.14.1 程序
import assert from 'node:assert/strict';

const run=function run(i,corrected=true){
    const frames=[];let pending='';for(const key of i.keys){if(key==='ENTER'){if(corrected){frames.push(pending);pending='';}}else pending+=key;}
    if(!corrected&&pending){frames.push(pending);pending='';}
    return {frames,pending,requiresReview:corrected&&(pending!==''||frames.some(f=>f.length!==3))};
  };
const cases=[{"input":{"keys":["A","1","2","ENTER","B","3","4","ENTER"]},"corrected":false,"expected":{"frames":["A12B34"],"pending":"","requiresReview":false}},{"input":{"keys":["A","1","2","ENTER","B","3","4","ENTER"]},"corrected":true,"expected":{"frames":["A12","B34"],"pending":"","requiresReview":false}},{"input":{"keys":["A","1","2","B","3","4","ENTER"]},"corrected":true,"expected":{"frames":["A12B34"],"pending":"","requiresReview":true}},{"input":{"keys":["A","1","2"]},"corrected":true,"expected":{"frames":[],"pending":"A12","requiresReview":true}}];
for(const test of cases){const actual=await run(test.input,test.corrected);assert.deepEqual(actual,test.expected);console.log(actual);}
下載可執行例子 ↓

按邊界依據作判斷

A12 未有終止鍵仍待完;六字完整段照留一段,列須覆核。

  1. 字元先放待完段
  2. 指定終止鍵才結段
  3. 查清單前先核段長

不能因代碼外觀熟悉就補終止鍵。

可編輯邊界輸入及結果
條件輸入 JSON預期輸出 JSON
只有一個合併段{"keys":["A","1","2","B","3","4","ENTER"]}{"frames":["A12B34"],"pending":"","requiresReview":true}
尾段未有終止鍵{"keys":["A","1","2"]}{"frames":[],"pending":"A12","requiresReview":true}
下載可編輯 CSV ↓

合段可否自動拆回 A12、B34?

查看參考答案

不能,只有一次終止鍵。A12B34 留作一段未解輸入,先補分段依據。

相關資源