JSFiddle - React, Tailwind, and code Playground
JavaScript
"use strict";
function sortCities(cities) {
cities.sort(function(a, b) { //результат функции больше нуля => ставим b перед a, меньше нуля -- наоборот
if (a.population < b.population) return 1;
if (a.population > b.population) return -1;
});
return cities;
}
var list = [{name: "Tokyo", country: "Japan", population: 13370198},
{name: "Delhi", country: "India", population: 11007835},
{name: "New York City", country: "USA", population: 8405837},
{name: "Moscow", country: "Russian Federation", population: 12197596},
{name: "London", country: "Great Britain", population: 8416999}];
var newList = sortCities(list);
console.log(newList);