Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let countrys ={
- Bulgaria: {
- Sofia:{
- population: 1242000
- },
- Plovdiv:{
- population: 669796
- }
- },
- Macedonia: {
- Skopje:{
- population: 627498
- },
- Ohrid:{
- population: 42000
- }
- }
- }
- let sorted = Object.keys(countrys).sort((a,b)=>
- getPop(countrys[b],'population') - getPop(countrys[a],'population') || a.localeCompare(b))
- sorted.forEach(element=>{
- console.log(`country: ${element}`);
- let town = countrys[element];
- let sort = Object.keys(town).sort((a,b)=>
- town[a].population - town[b].population
- )
- sort.forEach(el=>{
- console.log(`town: ${el} - population: ${town[el].population}`);
- })
- console.log('-'.repeat(50))
- })
- function getPop(country,type){
- let minNum = Number.MAX_SAFE_INTEGER;
- Object.keys(country).forEach(el=>{
- let minPopulation = country[el][type];// ili countrys
- if(minNum > minPopulation){
- minNum = minPopulation;
- }
- });
- return minNum;
- }
Advertisement
Add Comment
Please, Sign In to add comment