@@ -1327,27 +1327,26 @@ const makePatternKit = () => {
13271327 * @param {Pattern } elementPatt
13281328 * @param {bigint } bound Must be >= 1n
13291329 * @param {Rejector } reject
1330- * @param {T[] } [inResults]
1331- * @param {T[] } [outResults]
1330+ * @param {T[] | undefined } inResults
1331+ * @param {T[] | undefined } outResults
1332+ * @param {-1 | 1 } direction -1 for picking from the end (which gives
1333+ * intuitive results with descending lexicographic CopySet payloads); 1 for
1334+ * picking from the start (which gives intuitive results with other arrays)
13321335 * @returns {boolean }
13331336 */
13341337 const confirmElementsHasSplit = (
13351338 elements ,
13361339 elementPatt ,
13371340 bound ,
13381341 reject ,
1339- inResults = undefined ,
1340- outResults = undefined ,
1342+ inResults ,
1343+ outResults ,
1344+ direction ,
13411345 ) => {
13421346 let inCount = 0n ;
1343- // Since this feature is motivated by ERTP's use on
1344- // non-fungible (`set`, `copySet`) amounts,
1345- // their arrays store their elements in decending lexicographic order.
1346- // But this function has to make some choice amoung equally good minimal
1347- // results. It is more intuitive for the choice to be the first `bound`
1348- // matching elements in ascending lexicigraphic order, rather than
1349- // decending. Thus we iterate `elements` in reverse order.
1350- for ( let i = elements . length - 1 ; i >= 0 ; i -= 1 ) {
1347+ const firstIndex = direction === - 1 ? elements . length - 1 : 0 ;
1348+ const stopIndex = direction === - 1 ? - 1 : elements . length ;
1349+ for ( let i = firstIndex ; i !== stopIndex ; i += direction ) {
13511350 const element = elements [ i ] ;
13521351 if ( inCount >= bound ) {
13531352 if ( ! outResults ) break ;
@@ -1455,6 +1454,7 @@ const makePatternKit = () => {
14551454 reject ,
14561455 inResults ,
14571456 outResults ,
1457+ 1 ,
14581458 ) && harden ( [ inResults , outResults ] )
14591459 ) ;
14601460 }
@@ -1467,6 +1467,7 @@ const makePatternKit = () => {
14671467 reject ,
14681468 inResults ,
14691469 outResults ,
1470+ - 1 ,
14701471 ) &&
14711472 harden ( [
14721473 inResults && makeCopySet ( inResults ) ,
0 commit comments