loading...

re: JavaScript Bubble Sort in the fewest lines VIEW POST

FULL DISCUSSION
 

While working on a selection sort (posting soon), I realized I could have used a destructuring assignment to cut two lines from the function.

Turn:
swaps = true;
arr[ind] = arr[ind + 1];
arr[ind + 1] = val;

Into:
[arr[ind], arr[ind + 1], swaps] = [arr[ind +1], arr[ind], true];

I think it would make it less readable, but it would definitely make it shorter.

Code of Conduct Report abuse