Skip to main content
4 of 4
added 40 characters in body
Danny
  • 1.6k
  • 10
  • 17

ECMAScript 6, 61

Assumes z is the input

z.sort((a,b)=>{c=d=e=0;while(++c<32)d+=a>>c&1,e+=b>>c&1},e-d) 

Test data

[28943,825,11746,16375,32425,19944,21826,15752,15342,3944,28436].sort( (a,b)=>{ c=d=e=0; while(++c<32) d+=a>>c&1,e+=b>>c&1 },e-d ) [16375, 15342, 32425, 11746, 19944, 28436, 28943, 15752, 3944, 21826, 825] 

Thanks, toothbrush for the shorter solution.

Danny
  • 1.6k
  • 10
  • 17