Question: I have an object like this,

```
{
    "Distrubutor":"DISTRIBUTOR1",
    "INCLUDE":"INDIA,United States",
    "EXCLUDE":"KARNATAKA-INDIA,CHENNAI-TAMILNADU-INDIA",
    "PARENT-ID":""
}

```

i want to Generate the Multiple objecs By using the INCLUDE Property in the Main object, can anybody help me on this

```
{
    "parent_id":"",
    "id":"DISTRIBUTOR1",
    "permission":"Granted",
    "country_code":"INDIA"
}

2.  
{
    "parent_id":"",
    "id":"DISTRIBUTOR1",
    "permission":"Granted",
    "country_code":"United States"
}

```

Answer: 
You could split the included countries and map new objects.

```js
var data = {"Distrubutor":"DISTRIBUTOR1","INCLUDE":"INDIA,United States","EXCLUDE":"KARNATAKA-INDIA,CHENNAI-TAMILNADU-INDIA","PARENT-ID":""},
    include = data.INCLUDE.split(',').map(function (a) {
        return {
            parent_id: "",
            id: data.Distrubutor,
            permission: "Granted",
            country_code: a                
        };
    });

console.log(include);
```

```css
.as-console-wrapper { max-height: 100% !important; top: 0; }
```
This is another approach to solve current problem what could also be answer for possible new question "How could you make it more complex"

```js
class PropertyAdapter {
  *populate(target, option){}
}

class DistrubutorAdapter extends PropertyAdapter {
  *populate(target, option){
    target.id = option;
    yield target;
  }
}

class ParentIdAdapter extends PropertyAdapter {
  *populate(target, option){
    target.parent_id = option;
    yield target;
  }  
}

class IncludeAdapter extends PropertyAdapter {
  *populate(target, option){
    option = option.split(/,/g).map(x=>x.trim()).filter(x=>!!x.length);
    for(let v of option){
      let obj = Instantinator.copy(target);
      obj.country_code = v;
      yield obj;
    }
  }  
}

class Instantinator {
  static create(){
    return {permission: 'Granted'};
  }

  static copy(src){
    return Object.assign({}, src);
  }
}

const ADAPTERS = new Map();

class ObjectFactory {
  static register(prop, adapter){
    ADAPTERS.set(prop, adapter);
  }

  static create(options){
    const pairs = Object.keys(options||{})
      .filter(key => ADAPTERS.has(key))
      .map(key=> ({value: options[key], adapter: ADAPTERS.get(key)}));
    let result = [Instantinator.create()];
    for(let pair of pairs){
      result = result.reduce((prev, cur) => prev.concat([...pair.adapter.populate(cur, pair.value)]), []);
    }
    return result;
  }
}

ObjectFactory.register('Distrubutor', new DistrubutorAdapter());
ObjectFactory.register('PARENT-ID', new ParentIdAdapter());
ObjectFactory.register('INCLUDE', new IncludeAdapter());

var options = {
    "Distrubutor":"DISTRIBUTOR1",
    "INCLUDE":"INDIA,United States",
    "EXCLUDE":"KARNATAKA-INDIA,CHENNAI-TAMILNADU-INDIA",
    "PARENT-ID":""
};

console.log(ObjectFactory.create(options));
```

```css
.as-console-wrapper { max-height: 100% !important; top: 0; }
```