JSFiddle - React, Tailwind, and code Playground

by f0t0n

JavaScript

var conutries,
    manufacturers,
    i,
    len,
    country,
    manufacturerByCountry;
countries = ['China', 'China', 'Korea', 'USA', 'USA'];
manufacturers = ['Lenovo', 'Asus', 'Samsung', 'Apple', 'Blackberry'];
len = countries.length;
manufacturerByCountry = {};
// expected result:
// array : {'China': ['Lenovo', 'Asus'], 'Korea': ['Samsung'] ... }

for(i = 0; i < len; i++) {
    country = countries[i];
    if(!manufacturerByCountry[country]) {
        manufacturerByCountry[country] = [];
    }
    manufacturerByCountry[country].push(manufacturers[i]);
}

console.log(manufacturerByCountry);