title: Map Array elements and return objects
body: <p>I have an array of objects like this:</p>
  
  <pre><code>var pools = [{
      dce: 3,
      lts: 2,
      name: "nift nation",
    },
    {
      dce: 1049.99,
      lts: 104.999,
      name: "NSG I.NS. Mark Select",
    },
    {
      dce: 162,
      lts: 36.157,
      name: "Shift-Team Mark Select",
    }
  ]
  </code></pre>
  
  <p>I get: </p>
  
  <pre><code>[
    {
      "nift_nation": [
        {
          "nift_nationDollars": ""
        },
        {
          "nift_nationUnits": ""
        },
        {
          "nift_nationPercentage": ""
        }
      ]
    },
    {
      "NSG_I$NS$_Mark_Select": [
        {
          "NSG_I$NS$_Mark_SelectDollars": ""
        },
        {
          "NSG_I$NS$_Mark_SelectUnits": ""
        },
        {
          "NSG_I$NS$_Mark_SelectPercentage": ""
        }
      ]
    },
    {
      "Shift__Team_Mark_Select": [
        {
          "Shift__Team_Mark_SelectDollars": ""
        },
        {
          "Shift__Team_Mark_SelectUnits": ""
        },
        {
          "Shift__Team_Mark_SelectPercentage": ""
        }
      ]
    }
  ]
  </code></pre>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var pools = [{
      dce: 3,
      lts: 2,
      name: "nift nation",
    },
    {
      dce: 1049.99,
      lts: 104.999,
      name: "NSG I.NS. Mark Select",
    },
    {
      dce: 162,
      lts: 36.157,
      name: "Shift-Team Mark Select",
    }
  ]
  
  var getFieldSuffix = function(rowFieldCount) {
    switch (rowFieldCount) {
      case 0:
        return 'Dollars';
      case 1:
        return 'Units';
      case 2:
        return 'Percentage';
      default:
        return
    }
  };
  
  var replacementMap = {
    single_space: '_',
    dot: '$',
    hyphen: '__',
  };
  
  var replacer = function(str) {
    return str.replace(/[ .-]/g, l =&gt; {
      if (l == ".") return replacementMap["dot"];
      if (l == " ") return replacementMap["single_space"];
      return replacementMap["hyphen"];
    });
  };
  
  var arrObj = pools.map(function(pool) {
    return Object.assign({
      [replacer(pool.name)]: ['Dollars', 'Units', 'Percentage'].map(function(suffix, index) {
        return {
          [replacer(pool.name) + getFieldSuffix(index % 3)]: ''
        }
      })
    })
  })
  
  console.log(arrObj)</code></pre>
  </div>
  </div>
  </p>
  
  <p>I want: </p>
  
  <pre><code>{
    {
      "nift_nation": {
        "nift_nationDollars": "",
        "nift_nationUnits": "",
        "nift_nationPercentage": "",
      }
    },
    {
      "NSG_I$NS$_Mark_Select": {
        "NSG_I$NS$_Mark_SelectDollars": "",
        "NSG_I$NS$_Mark_SelectUnits": "",
        "NSG_I$NS$_Mark_SelectPercentage": "",
      }
    },
    {
      "Shift__Team_Mark_Select": {
        "Shift__Team_Mark_SelectDollars": "",
        "Shift__Team_Mark_SelectUnits": "",
        "Shift__Team_Mark_SelectPercentage": "",
      }
    } 
  }
  </code></pre>