Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
var n = +prompt("Сколько городов вывести?", "")
var populated = [
  {name: "Tokio", population: 37555},
  {name: "Jakarta", population: 29959},
  {name: "Deli", population: 24134}
];
function decrease(x, y) {
    if (x.population > y.population) {
        return -1;
    };
    if (x.population < y.population) {
        return 1;
    };
    return 0;
};
populated.sort(decrease);
for (var i = 0; i < n; i++) { 
    console.log(populated[i].name); 
};
         
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers