JavaScript

sort mutation in JavaScript

JavaScriptArrayschaining methodsintermediate

What this snippet does

sort, reverse, and splice mutate the original array — always spread or slice first when you want a non-destructive sort.

Expected output

original mutated: [ 1, 1, 3, 4, 5, 9 ]
original intact: [ 3, 1, 4, 1, 5, 9 ]

Why practise typing this

Typing arrays code builds muscle memory for the symbols and indentation JavaScript uses most, which prose-based typing tests never cover. DevType measures your words per minute and accuracy on this snippet and tracks the individual characters you mistype, so later lessons can target them.

More JavaScript practice

Browse all JavaScript snippets →