freecoding.school100% FREE · NO SIGNUP
Closure CavesISSUE #60 of 61

ES2023 · array find from last · symbol.dispose

LambdaVSThe Mutator
Lambda saysES2023 added immutable array methods (toSorted, toReversed) and findLast.

New non-mutating array methods return a copy instead of changing the original: toSorted, toReversed, toSpliced, and with (replace one index). findLast/findLastIndex search from the end. These remove a whole class of "oops, I mutated it" bugs that plagued sort and reverse.

Power-ups you unlock

The Mutator attacks — common mistakes

Boss battleSort an array immutably with toSorted and prove the original is unchanged.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre id="o"></pre>
<script>const orig=[3,1,2];const sorted=orig.toSorted((a,b)=>a-b);
document.getElementById('o').textContent='orig='+orig+'\nsorted='+sorted;</script></body></html>
▶ Open the interactive comic issue
‹ ES2022 · Top-Level Await · #Private FieldsES2024 · GroupBy · Promise.WithResolvers ›