DEV Community

Discussion on: JavaScript Bubble Sort in the fewest lines

letmypeoplecode profile image
Greg Bulmash 🥑 Author

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

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

[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.