skip to Main Content

Good afternoon
I’m trying to merge 2 object by assigning some values to a number of element the other number to another number of elements. I managed to create some thing but it places some on the wrong position an the code is repetitive.
Here is my code

const data = [
  [
      "Greece"
  ],
  [
      "Denmark"
  ],
  [
      "Finland"
  ],
  [
      "Norway"
  ],
  [
      "Sweden"
  ],
  [
      "Portugal"
  ],
  [
      "Austria"
  ],
  [
      "Belgium"
  ],
  [
      "Bulgaria"
  ],
  [
      "Croatia"
  ],
  [
      "Cyprus"
  ],
  [
      "Czech Republic"
  ],
  [
      "Estonia"
  ],
  [
      "France"
  ],
  [
      "Germany (Federal Republic of)"
  ],
  [
      "Gibraltar"
  ],
  [
      "Hungary"
  ],
  [
      "Iceland"
  ],
  [
      "Ireland"
  ],
  [
      "Italy"
  ],
  [
      "Latvia"
  ],
  [
      "Liechtenstein"
  ],
  [
      "Lithuania"
  ],
  [
      "Luxembourg"
  ],
  [
      "Malta"
  ],
  [
      "Netherlands"
  ],
  [
      "Poland"
  ],
  [
      "Reunion"
  ],
  [
      "Romania"
  ],
  [
      "Saint Pierre and Miquelon (Collectivité territoriale de la République française)"
  ],
  [
      "Slovak Republic"
  ],
  [
      "Slovenia"
  ],
  [
      "Spain"
  ],
  [
      "Switzerland"
  ],
  [
      "United Kingdom of Great Britain and Northern Ireland"
  ],
  [
      "Kazakhstan"
  ],
  [
      "Turkey"
  ],
  [
      "Bosnia and Herzegovina"
  ],
  [
      "Faroe Islands"
  ],
  [
      "Israel"
  ],
  [
      "Macau"
  ],
  [
      "Azerbaijan"
  ],
  [
      "Guadeloupe"
  ],
  [
      "Fiji"
  ],
  [
      "Samoa"
  ],
  [
      "Tonga"
  ],
  [
      "Canada"
  ],
  [
      "United States of America"
  ],
  [
      "Monaco"
  ],
  [
      "Bermuda"
  ],
  [
      "Costa Rica"
  ],
  [
      "Guatemala"
  ],
  [
      "Guyana"
  ],
  [
      "Honduras"
  ],
  [
      "Papua New Guinea"
  ],
  [
      "Paraguay"
  ],
  [
      "Albania"
  ],
  [
      "Cambodia"
  ],
  [
      "Sri Lanka"
  ],
  [
      "Dominican Republic"
  ],
  [
      "Ecuador"
  ],
  [
      "Mongolia"
  ],
  [
      "Nicaragua"
  ],
  [
      "Vietnam"
  ],
  [
      "Jordan"
  ],
  [
      "Namibia"
  ],
  [
      "Afghanistan"
  ],
  [
      "Argentina"
  ],
  [
      "Botswana"
  ],
  [
      "Cameroon"
  ],
  [
      "Congo"
  ],
  [
      "Cote d'Ivoire"
  ],
  [
      "Falkland Islands (Malvinas)"
  ],
  [
      "Ghana"
  ],
  [
      "Guinea"
  ],
  [
      "Guinea-Bissau"
  ],
  [
      "Kosovo"
  ],
  [
      "Liberia"
  ],
  [
      "Madagascar"
  ],
  [
      "Moldova"
  ],
  [
      "Nigeria"
  ],
  [
      "Republic of Rwanda"
  ],
  [
      "Senegal"
  ],
  [
      "Somalia"
  ],
  [
      "South Africa"
  ],
  [
      "Swaziland"
  ],
  [
      "Syrian Arab Republic"
  ],
  [
      "Uganda"
  ],
  [
      "Zambia"
  ],
  [
      "Mexico"
  ],
  [
      "Andorra"
  ],
  [
      "Belarus"
  ],
  [
      "Greenland (Denmark)"
  ],
  [
      "Montenegro"
  ],
  [
      "Serbia"
  ],
  [
      "Sierra Leone"
  ],
  [
      "The Former Yugoslav Republic of Macedonia"
  ],
  [
      "Ukraine"
  ],
  [
      "Russian Federation"
  ],
  [
      "Burkina Faso"
  ],
  [
      "Central African Republic"
  ],
  [
      "Niger"
  ],
  [
      "Democratic Republic of Congo"
  ],
  [
      "Armenia"
  ],
  [
      "Philippines"
  ],
  [
      "China"
  ],
  [
      "Gabon"
  ],
  [
      "Malawi"
  ],
  [
      "Japan"
  ],
  [
      "Kenya"
  ],
  [
      "Kyrgyzstan"
  ],
  [
      "Panama"
  ],
  [
      "Bangladesh"
  ],
  [
      "Georgia"
  ],
  [
      "Pakistan"
  ],
  [
      "Singapore"
  ],
  [
      "Chad"
  ],
  [
      "Indonesia"
  ],
  [
      "El Salvador"
  ],
  [
      "Algeria"
  ],
  [
      "Bahrain"
  ],
  [
      "Benin"
  ],
  [
      "Brunei Darussalam"
  ],
  [
      "Iran"
  ],
  [
      "Laos"
  ],
  [
      "Malaysia"
  ],
  [
      "Mali"
  ],
  [
      "Togo"
  ],
  [
      "Uzbekistan"
  ],
  [
      "Tanzania"
  ],
  [
      "Thailand"
  ],
  [
      "Mauritius"
  ],
  [
      "Anguilla"
  ],
  [
      "Antigua and Barbuda"
  ],
  [
      "Barbados"
  ],
  [
      "British Virgin Islands"
  ],
  [
      "Cayman Islands"
  ],
  [
      "Dominica"
  ],
  [
      "Grenada"
  ],
  [
      "Jamaica"
  ],
  [
      "Montserrat"
  ],
  [
      "Saint Kitts and Nevis"
  ],
  [
      "Saint Lucia"
  ],
  [
      "Saint Vincent and the Grenadines"
  ],
  [
      "Virgin Islands"
  ],
  [
      "Tunisia"
  ],
  [
      "Chile"
  ],
  [
      "Australia"
  ],
  [
      "Cabo Verde"
  ],
  [
      "Curaçao"
  ],
  [
      "Myanmar"
  ],
  [
      "Gambia"
  ],
  [
      "Brazil"
  ],
  [
      "Suriname"
  ],
  [
      "Trinidad and Tobago"
  ],
  [
      "Qatar"
  ],
  [
      "Seychelles"
  ],
  [
      "Burundi"
  ],
  [
      "French Polynesia"
  ],
  [
      "Haiti"
  ],
  [
      "Bolivia"
  ],
  [
      "Belize"
  ],
  [
      "Hong Kong"
  ],
  [
      "Taiwan"
  ],
  [
      "Kuwait"
  ],
  [
      "Zimbabwe"
  ],
  [
      "Nepal"
  ],
  [
      "New Zealand"
  ],
  [
      "Egypt"
  ],
  [
      "Angola"
  ],
  [
      "Lesotho"
  ],
  [
      "Mozambique"
  ],
  [
      "Puerto Rico"
  ],
  [
      "Peru"
  ],
  [
      "Equatorial Guinea"
  ],
  [
      "Uruguay"
  ],
  [
      "Venezuela"
  ],
  [
      "India"
  ],
  [
      "Maldives"
  ],
  [
      "Republic of Korea"
  ],
  [
      "Turkmenistan"
  ],
  [
      "Tajikistan"
  ],
  [
      "Cuba"
  ],
  [
      "Saudi Arabia"
  ],
  [
      "Timor-Leste"
  ],
  [
      "Iraq"
  ],
  [
      "Libya"
  ],
  [
      "Mauritania"
  ],
  [
      "Morocco"
  ],
  [
      "Republic of Djibouti"
  ],
  [
      "Sudan"
  ],
  [
      "Lebanon"
  ],
  [
      "Oman"
  ],
  [
      "United Arab Emirates"
  ],
  [
      "Yemen"
  ]
];

const preset = [
  {
    "zone": 5821,
    "count": 36
  },
  {
    "zone": 5822,
    "count": 12
  },
  {
    "zone": 5823,
    "count": 53
  },
  {
    "zone": 5824,
    "count": 28
  },
  {
    "zone": 5825,
    "count": 27
  },
  {
    "zone": 5826,
    "count": 16
  },
  {
    "zone": 5827,
    "count": 23
  }
];

const myArr = [];

for (let i = 0; i < preset.length; i++) {
  for (let t = 0; t < preset[i].count; t++) {
    myArr.push({
      zone: preset[i].zone,
      country: data[t][0],
      number: i + 1
    });
  }
}

It produces the following results.

[ { zone: 5821, country: 'Greece', number: 1 },
  { zone: 5821, country: 'Denmark', number: 1 },
  { zone: 5821, country: 'Finland', number: 1 },
  { zone: 5821, country: 'Norway', number: 1 },
  { zone: 5821, country: 'Sweden', number: 1 },
  { zone: 5821, country: 'Portugal', number: 1 },
  { zone: 5821, country: 'Austria', number: 1 },
  { zone: 5821, country: 'Belgium', number: 1 },
  { zone: 5821, country: 'Bulgaria', number: 1 },
  { zone: 5821, country: 'Croatia', number: 1 },
  { zone: 5821, country: 'Cyprus', number: 1 },
  { zone: 5821, country: 'Czech Republic', number: 1 },
  { zone: 5821, country: 'Estonia', number: 1 },
  { zone: 5821, country: 'France', number: 1 },
  { zone: 5821,
    country: 'Germany (Federal Republic of)',
    number: 1 },
  { zone: 5821, country: 'Gibraltar', number: 1 },
  { zone: 5821, country: 'Hungary', number: 1 },
  { zone: 5821, country: 'Iceland', number: 1 },
  { zone: 5821, country: 'Ireland', number: 1 },
  { zone: 5821, country: 'Italy', number: 1 },
  { zone: 5821, country: 'Latvia', number: 1 },
  { zone: 5821, country: 'Liechtenstein', number: 1 },
  { zone: 5821, country: 'Lithuania', number: 1 },
  { zone: 5821, country: 'Luxembourg', number: 1 },
  { zone: 5821, country: 'Malta', number: 1 },
  { zone: 5821, country: 'Netherlands', number: 1 },
  { zone: 5821, country: 'Poland', number: 1 },
  { zone: 5821, country: 'Reunion', number: 1 },
  { zone: 5821, country: 'Romania', number: 1 },
  { zone: 5821,
    country: 'Saint Pierre and Miquelon (Collectivité territoriale de la République française)',
    number: 1 },
  { zone: 5821, country: 'Slovak Republic', number: 1 },
  { zone: 5821, country: 'Slovenia', number: 1 },
  { zone: 5821, country: 'Spain', number: 1 },
  { zone: 5821, country: 'Switzerland', number: 1 },
  { zone: 5821,
    country: 'United Kingdom of Great Britain and Northern Ireland',
    number: 1 },
  { zone: 5821, country: 'Kazakhstan', number: 1 },
  { zone: 5822, country: 'Greece', number: 2 },
  { zone: 5822, country: 'Denmark', number: 2 },
  { zone: 5822, country: 'Finland', number: 2 },
  { zone: 5822, country: 'Norway', number: 2 },
  { zone: 5822, country: 'Sweden', number: 2 },
  { zone: 5822, country: 'Portugal', number: 2 },
  { zone: 5822, country: 'Austria', number: 2 },
  { zone: 5822, country: 'Belgium', number: 2 },
  { zone: 5822, country: 'Bulgaria', number: 2 },
  { zone: 5822, country: 'Croatia', number: 2 },
  { zone: 5822, country: 'Cyprus', number: 2 },
  { zone: 5822, country: 'Czech Republic', number: 2 },
  { zone: 5823, country: 'Greece', number: 3 },
  { zone: 5823, country: 'Denmark', number: 3 },
  { zone: 5823, country: 'Finland', number: 3 },
  { zone: 5823, country: 'Norway', number: 3 },
  { zone: 5823, country: 'Sweden', number: 3 },
  { zone: 5823, country: 'Portugal', number: 3 },
  { zone: 5823, country: 'Austria', number: 3 },
  { zone: 5823, country: 'Belgium', number: 3 },
  { zone: 5823, country: 'Bulgaria', number: 3 },
  { zone: 5823, country: 'Croatia', number: 3 },
  { zone: 5823, country: 'Cyprus', number: 3 },
  { zone: 5823, country: 'Czech Republic', number: 3 },
  { zone: 5823, country: 'Estonia', number: 3 },
  { zone: 5823, country: 'France', number: 3 },
  { zone: 5823,
    country: 'Germany (Federal Republic of)',
    number: 3 },
  { zone: 5823, country: 'Gibraltar', number: 3 },
  { zone: 5823, country: 'Hungary', number: 3 },
  { zone: 5823, country: 'Iceland', number: 3 },
  { zone: 5823, country: 'Ireland', number: 3 },
  { zone: 5823, country: 'Italy', number: 3 },
  { zone: 5823, country: 'Latvia', number: 3 },
  { zone: 5823, country: 'Liechtenstein', number: 3 },
  { zone: 5823, country: 'Lithuania', number: 3 },
  { zone: 5823, country: 'Luxembourg', number: 3 },
  { zone: 5823, country: 'Malta', number: 3 },
  { zone: 5823, country: 'Netherlands', number: 3 },
  { zone: 5823, country: 'Poland', number: 3 },
  { zone: 5823, country: 'Reunion', number: 3 },
  { zone: 5823, country: 'Romania', number: 3 },
  { zone: 5823,
    country: 'Saint Pierre and Miquelon (Collectivité territoriale de la République française)',
    number: 3 },
  { zone: 5823, country: 'Slovak Republic', number: 3 },
  { zone: 5823, country: 'Slovenia', number: 3 },
  { zone: 5823, country: 'Spain', number: 3 },
  { zone: 5823, country: 'Switzerland', number: 3 },
  { zone: 5823,
    country: 'United Kingdom of Great Britain and Northern Ireland',
    number: 3 },
  { zone: 5823, country: 'Kazakhstan', number: 3 },
  { zone: 5823, country: 'Turkey', number: 3 },
  { zone: 5823, country: 'Bosnia and Herzegovina', number: 3 },
  { zone: 5823, country: 'Faroe Islands', number: 3 },
  { zone: 5823, country: 'Israel', number: 3 },
  { zone: 5823, country: 'Macau', number: 3 },
  { zone: 5823, country: 'Azerbaijan', number: 3 },
  { zone: 5823, country: 'Guadeloupe', number: 3 },
  { zone: 5823, country: 'Fiji', number: 3 },
  { zone: 5823, country: 'Samoa', number: 3 },
  { zone: 5823, country: 'Tonga', number: 3 },
  { zone: 5823, country: 'Canada', number: 3 },
  { zone: 5823, country: 'United States of America', number: 3 },
  { zone: 5823, country: 'Monaco', number: 3 },
  { zone: 5823, country: 'Bermuda', number: 3 },
  { zone: 5823, country: 'Costa Rica', number: 3 },
  { zone: 5823, country: 'Guatemala', number: 3 },
  { zone: 5823, country: 'Guyana', number: 3 },
  { zone: 5824, country: 'Greece', number: 4 },
  { zone: 5824, country: 'Denmark', number: 4 },
  { zone: 5824, country: 'Finland', number: 4 },
  { zone: 5824, country: 'Norway', number: 4 },
  { zone: 5824, country: 'Sweden', number: 4 },
  { zone: 5824, country: 'Portugal', number: 4 },
  { zone: 5824, country: 'Austria', number: 4 },
  { zone: 5824, country: 'Belgium', number: 4 },
  { zone: 5824, country: 'Bulgaria', number: 4 },
  { zone: 5824, country: 'Croatia', number: 4 },
  { zone: 5824, country: 'Cyprus', number: 4 },
  { zone: 5824, country: 'Czech Republic', number: 4 },
  { zone: 5824, country: 'Estonia', number: 4 },
  { zone: 5824, country: 'France', number: 4 },
  { zone: 5824,
    country: 'Germany (Federal Republic of)',
    number: 4 },
  { zone: 5824, country: 'Gibraltar', number: 4 },
  { zone: 5824, country: 'Hungary', number: 4 },
  { zone: 5824, country: 'Iceland', number: 4 },
  { zone: 5824, country: 'Ireland', number: 4 },
  { zone: 5824, country: 'Italy', number: 4 },
  { zone: 5824, country: 'Latvia', number: 4 },
  { zone: 5824, country: 'Liechtenstein', number: 4 },
  { zone: 5824, country: 'Lithuania', number: 4 },
  { zone: 5824, country: 'Luxembourg', number: 4 },
  { zone: 5824, country: 'Malta', number: 4 },
  { zone: 5824, country: 'Netherlands', number: 4 },
  { zone: 5824, country: 'Poland', number: 4 },
  { zone: 5824, country: 'Reunion', number: 4 },
  { zone: 5825, country: 'Greece', number: 5 },
  { zone: 5825, country: 'Denmark', number: 5 },
  { zone: 5825, country: 'Finland', number: 5 },
  { zone: 5825, country: 'Norway', number: 5 },
  { zone: 5825, country: 'Sweden', number: 5 },
  { zone: 5825, country: 'Portugal', number: 5 },
  { zone: 5825, country: 'Austria', number: 5 },
  { zone: 5825, country: 'Belgium', number: 5 },
  { zone: 5825, country: 'Bulgaria', number: 5 },
  { zone: 5825, country: 'Croatia', number: 5 },
  { zone: 5825, country: 'Cyprus', number: 5 },
  { zone: 5825, country: 'Czech Republic', number: 5 },
  { zone: 5825, country: 'Estonia', number: 5 },
  { zone: 5825, country: 'France', number: 5 },
  { zone: 5825,
    country: 'Germany (Federal Republic of)',
    number: 5 },
  { zone: 5825, country: 'Gibraltar', number: 5 },
  { zone: 5825, country: 'Hungary', number: 5 },
  { zone: 5825, country: 'Iceland', number: 5 },
  { zone: 5825, country: 'Ireland', number: 5 },
  { zone: 5825, country: 'Italy', number: 5 },
  { zone: 5825, country: 'Latvia', number: 5 },
  { zone: 5825, country: 'Liechtenstein', number: 5 },
  { zone: 5825, country: 'Lithuania', number: 5 },
  { zone: 5825, country: 'Luxembourg', number: 5 },
  { zone: 5825, country: 'Malta', number: 5 },
  { zone: 5825, country: 'Netherlands', number: 5 },
  { zone: 5825, country: 'Poland', number: 5 },
  { zone: 5826, country: 'Greece', number: 6 },
  { zone: 5826, country: 'Denmark', number: 6 },
  { zone: 5826, country: 'Finland', number: 6 },
  { zone: 5826, country: 'Norway', number: 6 },
  { zone: 5826, country: 'Sweden', number: 6 },
  { zone: 5826, country: 'Portugal', number: 6 },
  { zone: 5826, country: 'Austria', number: 6 },
  { zone: 5826, country: 'Belgium', number: 6 },
  { zone: 5826, country: 'Bulgaria', number: 6 },
  { zone: 5826, country: 'Croatia', number: 6 },
  { zone: 5826, country: 'Cyprus', number: 6 },
  { zone: 5826, country: 'Czech Republic', number: 6 },
  { zone: 5826, country: 'Estonia', number: 6 },
  { zone: 5826, country: 'France', number: 6 },
  { zone: 5826,
    country: 'Germany (Federal Republic of)',
    number: 6 },
  { zone: 5826, country: 'Gibraltar', number: 6 },
  { zone: 5827, country: 'Greece', number: 7 },
  { zone: 5827, country: 'Denmark', number: 7 },
  { zone: 5827, country: 'Finland', number: 7 },
  { zone: 5827, country: 'Norway', number: 7 },
  { zone: 5827, country: 'Sweden', number: 7 },
  { zone: 5827, country: 'Portugal', number: 7 },
  { zone: 5827, country: 'Austria', number: 7 },
  { zone: 5827, country: 'Belgium', number: 7 },
  { zone: 5827, country: 'Bulgaria', number: 7 },
  { zone: 5827, country: 'Croatia', number: 7 },
  { zone: 5827, country: 'Cyprus', number: 7 },
  { zone: 5827, country: 'Czech Republic', number: 7 },
  { zone: 5827, country: 'Estonia', number: 7 },
  { zone: 5827, country: 'France', number: 7 },
  { zone: 5827,
    country: 'Germany (Federal Republic of)',
    number: 7 },
  { zone: 5827, country: 'Gibraltar', number: 7 },
  { zone: 5827, country: 'Hungary', number: 7 },
  { zone: 5827, country: 'Iceland', number: 7 },
  { zone: 5827, country: 'Ireland', number: 7 },
  { zone: 5827, country: 'Italy', number: 7 },
  { zone: 5827, country: 'Latvia', number: 7 },
  { zone: 5827, country: 'Liechtenstein', number: 7 },
  { zone: 5827, country: 'Lithuania', number: 7 } ]

As you can see zone: 5820 is assigned to Iraq but it is not supposed to do that. I would like some help.

Expected results each zone is supposed to be assigned to with countries from index 0 to 35 which is the count element in the preset but It repeats and I see the issue I just can’t figure it out.
My plan was for each zone loop count times and assign countries but I didn’t foresee that it will start from index 0 every count

Thanks in advance

2

Answers


  1. What is it supposed to do then?

    From Your code below

    if (**i <= 2**) {
    myArr.push({
      zone: preset[0].zone,
      country: data[i][0],
      number: 1
    });
    }
    

    Above will run for i = 0, 1 and 2, which is Saudi, Timor and Iraq. If you want all of the zones to only be applied to two items, then change your if logic to say below

    if (i <= 1) {
        myArr.push({
          zone: preset[0].zone,
          country: data[i][0],
          number: 1
        });
      } 
      else if (i > 1 && i <= 3) {
        myArr.push({
          zone: preset[1].zone,
          country: data[i][0],
          number: 2
        });
      }
      else if (i > 3 && i <= 5) {
        myArr.push({
          zone: preset[2].zone,
          country: data[i][0],
          number: 3
        });
      }
      else if (i > 5 && i <= 7) {
        myArr.push({
          zone: preset[3].zone,
          country: data[i][0],
          number: 4
        });
      }
      else if (i > 7 && i <= 9) {
        myArr.push({
          zone: preset[4].zone,
          country: data[i][0],
          number: 5
        });
      }
      else if (i > 9 && i <= 11) {
        myArr.push({
          zone: preset[5].zone,
          country: data[i][0],
          number: 6
        });
      }
      else {
        console.log("TEST");
      }
    

    You can also simplify the entire thing to say

    index = Math.floor(i/2)
    myArr.push({
      zone: preset[index].zone,
      country: data[i][0],
      number: index+1
    });
    
    Login or Signup to reply.
  2. You can use Array#flatMap and store the current index in a closure.

    const data=[["Greece"],["Denmark"],["Finland"],["Norway"],["Sweden"],["Portugal"],["Austria"],["Belgium"],["Bulgaria"],["Croatia"],["Cyprus"],["Czech Republic"],["Estonia"],["France"],["Germany (Federal Republic of)"],["Gibraltar"],["Hungary"],["Iceland"],["Ireland"],["Italy"],["Latvia"],["Liechtenstein"],["Lithuania"],["Luxembourg"],["Malta"],["Netherlands"],["Poland"],["Reunion"],["Romania"],["Saint Pierre and Miquelon (Collectivitxe9 territoriale de la Rxe9publique franxe7aise)"],["Slovak Republic"],["Slovenia"],["Spain"],["Switzerland"],["United Kingdom of Great Britain and Northern Ireland"],["Kazakhstan"],["Turkey"],["Bosnia and Herzegovina"],["Faroe Islands"],["Israel"],["Macau"],["Azerbaijan"],["Guadeloupe"],["Fiji"],["Samoa"],["Tonga"],["Canada"],["United States of America"],["Monaco"],["Bermuda"],["Costa Rica"],["Guatemala"],["Guyana"],["Honduras"],["Papua New Guinea"],["Paraguay"],["Albania"],["Cambodia"],["Sri Lanka"],["Dominican Republic"],["Ecuador"],["Mongolia"],["Nicaragua"],["Vietnam"],["Jordan"],["Namibia"],["Afghanistan"],["Argentina"],["Botswana"],["Cameroon"],["Congo"],["Cote d'Ivoire"],["Falkland Islands (Malvinas)"],["Ghana"],["Guinea"],["Guinea-Bissau"],["Kosovo"],["Liberia"],["Madagascar"],["Moldova"],["Nigeria"],["Republic of Rwanda"],["Senegal"],["Somalia"],["South Africa"],["Swaziland"],["Syrian Arab Republic"],["Uganda"],["Zambia"],["Mexico"],["Andorra"],["Belarus"],["Greenland (Denmark)"],["Montenegro"],["Serbia"],["Sierra Leone"],["The Former Yugoslav Republic of Macedonia"],["Ukraine"],["Russian Federation"],["Burkina Faso"],["Central African Republic"],["Niger"],["Democratic Republic of Congo"],["Armenia"],["Philippines"],["China"],["Gabon"],["Malawi"],["Japan"],["Kenya"],["Kyrgyzstan"],["Panama"],["Bangladesh"],["Georgia"],["Pakistan"],["Singapore"],["Chad"],["Indonesia"],["El Salvador"],["Algeria"],["Bahrain"],["Benin"],["Brunei Darussalam"],["Iran"],["Laos"],["Malaysia"],["Mali"],["Togo"],["Uzbekistan"],["Tanzania"],["Thailand"],["Mauritius"],["Anguilla"],["Antigua and Barbuda"],["Barbados"],["British Virgin Islands"],["Cayman Islands"],["Dominica"],["Grenada"],["Jamaica"],["Montserrat"],["Saint Kitts and Nevis"],["Saint Lucia"],["Saint Vincent and the Grenadines"],["Virgin Islands"],["Tunisia"],["Chile"],["Australia"],["Cabo Verde"],["Curaxe7ao"],["Myanmar"],["Gambia"],["Brazil"],["Suriname"],["Trinidad and Tobago"],["Qatar"],["Seychelles"],["Burundi"],["French Polynesia"],["Haiti"],["Bolivia"],["Belize"],["Hong Kong"],["Taiwan"],["Kuwait"],["Zimbabwe"],["Nepal"],["New Zealand"],["Egypt"],["Angola"],["Lesotho"],["Mozambique"],["Puerto Rico"],["Peru"],["Equatorial Guinea"],["Uruguay"],["Venezuela"],["India"],["Maldives"],["Republic of Korea"],["Turkmenistan"],["Tajikistan"],["Cuba"],["Saudi Arabia"],["Timor-Leste"],["Iraq"],["Libya"],["Mauritania"],["Morocco"],["Republic of Djibouti"],["Sudan"],["Lebanon"],["Oman"],["United Arab Emirates"],["Yemen"]],preset=[{zone:5821,count:36},{zone:5822,count:12},{zone:5823,count:53},{zone:5824,count:28},{zone:5825,count:27},{zone:5826,count:16},{zone:5827,count:23}];
    const res = preset.flatMap((c => (o, i) => data.slice(c, c += o.count).map(x => ({
        zone: o.zone,
        country: x[0],
        number: i + 1
    })))(0));
    console.log(res);
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search