No sorting in Array, for whatever I try

No sorting in Array, for whatever I try

I've got following code and I dunno why the hell the output won't get sorted, as I will explain further on:


  1. /* 
  2. Author: Jennifer Eberlei
  3. Project: World-Map
  4. Date: 06-02-2013 // 07-02-2013
  5.  */


  6. $(document).ready(function() {
  7.     
  8.     function getWorldMapCoordinates() {  
  9.         var arr = new Array();
  10.         arr = [
  11.         {
  12.             name: "Deutschland",
  13.             numPosts: 14,
  14.             coordinates: {
  15.                 x: 50,  
  16.                 y: 50
  17.             },
  18.             link: "http://google.de/search?q=deutschland"
  19.         },
  20.         {
  21.             name: "Albanien",
  22.             numPosts: 33,
  23.             coordinates: {
  24.                 x: 65,
  25.                 y: 30
  26.             },
  27.             link: "http://google.de/search?q=albanien"
  28.         },
  29.         {
  30.             name: "Saudi-Arabien",
  31.             numPosts: 126,
  32.             coordinates: {
  33.                 x: 55,
  34.                 y: 70
  35.             },
  36.             link: "http://google.de/search?q=saudi-arabien"
  37.         },
  38.         {
  39.             name: "China",
  40.             numPosts: 33,
  41.             coordinates: {
  42.                 x: 30,
  43.                 y: 35
  44.             },
  45.             link: "http://google.de/search?q=china"
  46.         }
  47.         ];
  48.         
  49.        
  50.         // Füge Wrapper hinzu
  51.         $('body').prepend($('<div id="world-map-content">'));
  52.         
  53.         $.each(arr, function(key, value) { 
  54.             // Create Objects
  55.             $link = value.link;
  56.             $name = value.name;
  57.             $coords_x = value.coordinates.x;
  58.             $coords_y = value.coordinates.y;
  59.             $num = value.numPosts;
  60.             $newsize = $num * 1.5;
  61.             $margin = $newsize * 0.5;
  62.             
  63.             
  64.             // make new array of numPosts
  65.             
  66.             var maxi = new Array();
  67.             maxi = [
  68.                 anzahl = $num
  69.             ];
  70.             
  71.             
  72.            var maxi2 = maxi.anzahl;
  73.            
  74.            $newew = maxi2.sort();
  75.            console.log($newew);
  76.             $new = maxi.sort(function(b, a) {
  77.                 var a = anzahl;
  78.                 var b = anzahl;
  79.                 return a > b ? 1 : a < b ? -1 : 0;
  80.             });
  81.              console.log($new);
  82.   
  83.            
  84.             // Do some Markup
  85.             $('#world-map-content').append(
  86.                 $('<div class="world-map-entry ' + [key] + '"><div class="world-map-entry-bg" style="left:' + $coords_x + '%; top:' + $coords_y + '%; width:' + $newsize + 'px; height: ' + $newsize + 'px; margin-left: -' + $margin + 'px; margin-top: -' + $margin + 'px;"><img class="world-map-entry-circle" style="width:' + $newsize + 'px;height="' + $newsize + 'px;" src="img/circle.png" /></div>') 
  87.                 // Styles for reuse
  88.                 // style="left: 50%; top: 50%; width: 100px; height: 100px; margin-left: -50px; margin-top: -50px;"
  89.                 );  
  90.             $('.'+ key + '').append('<div class="world-map-entry-text" style="left:' + $coords_x + '%; top:' + $coords_y + '%; width:' + $newsize + 'px; height: ' + $newsize + 'px; margin-left: -' + $margin + 'px; margin-top: 0px;" ><a href="' + $link +'" title="' + $name + '">' + $name + '</a></div></div>'); 
  91.        
  92.         });


  93.        
  94.     // +++ End Schleife +++ 
  95.     // $('body').append($('</div>'));  
  96.     }  
  97.     // sort please
  98.         
  99.         
  100.         
  101.         
  102.         
  103.         
  104.     // +++ End of sorting
  105.         
  106.       
  107.         
  108.  


  109.     getWorldMapCoordinates();  
  110. });
So well, I want the numPosts in Array to be sorted descending as I need it for setting up a z-index to the .each() option, because I want to display further on somekinda world-map with circles, which can be overlayed by each other. They will've got different sizes, so I'll need the option to display smaller circles above bigger circles.

I'm open to any suggestions and questions