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:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user