© 2026 LinearBytes Inc.
Search posts, tags, users, and pages
Tony B
Nice article.
If performance isn't a huge concern, you can also just do this.
arr.sort((a,b) => !!b - !!a)
In recent versions of JavaScript the array sort is stable so the order of equal elements from the compare remains unchanged