Sorting by bits KATA from CodeWars: In this kata you're expected to sort an array of 32-bit integers in ascending order of the number of on bits they have.
function sortByBit(arr) {
const countBit = (bit) => bit.toString(2).replace(/[0]/g,
"").length;
return arr.sort((a, b) => countBit(a) === countBit(b) ? a
- b : countBit(a) - countBit(b));
}