js-on-sx: Array.prototype flat + fill; fix indexOf start arg

flat: walk with depth, recursive when element is list and depth>0.
fill(value, start?, end?): in-place mutation, returns self.
indexOf: honor second arg as start position.

396/398 unit (+5), 148/148 slice unchanged.
This commit is contained in:
2026-04-23 21:28:50 +00:00
parent e195b5bd72
commit 835025ec37
2 changed files with 71 additions and 1 deletions

View File

@@ -1015,6 +1015,18 @@ cat > "$TMPFILE" << 'EPOCHS'
(epoch 2009)
(eval "(js-eval \"JSON.parse('{\\\"a\\\":1}').a\")")
;; ── Phase 11.array2: flat + fill + indexOf start ───────────────
(epoch 2100)
(eval "(js-eval \"[1,[2,3],4].flat().length\")")
(epoch 2101)
(eval "(js-eval \"[1,[2,[3]]].flat(2).length\")")
(epoch 2102)
(eval "(js-eval \"[1,2,3].fill(0).join(',')\")")
(epoch 2103)
(eval "(js-eval \"[1,2,3,4].fill(0, 1, 3).join(',')\")")
(epoch 2104)
(eval "(js-eval \"[1,2,1,2].indexOf(2, 2)\")")
EPOCHS
@@ -1559,6 +1571,13 @@ check 2007 "parse string" '"hello"'
check 2008 "parse array length" '3'
check 2009 "parse object.a" '1'
# ── Phase 11.array2 ────────────────────────────────────────────
check 2100 "flat() depth 1" '4'
check 2101 "flat(2)" '3'
check 2102 "fill(0)" '"0,0,0"'
check 2103 "fill(0,1,3)" '"1,0,0,4"'
check 2104 "indexOf with start" '3'
TOTAL=$((PASS + FAIL))
if [ $FAIL -eq 0 ]; then
echo "$PASS/$TOTAL JS-on-SX tests passed"