module.exports = {
  /**
   * Creates a metrics object out of format string and data
   * @param format format.string
   * @param data { avgpower: 1234, energy: 4321 }
   * @returns {{}} { format.string: { avgpower: 1234, energy: 4321} || { power: 1313 } }
   */
  create: function create(format, data) {
    var formatArray = format.split('.'),
      properties = formatArray.slice(0),
      metric = {};
    metric[properties.pop()] = data.power ?
      {
        power: data.power
      }
      :
      {
        avgpower: data.avgpower,
        energy: data.energy
      };
    while (properties.length > 0) {
      var temp = {};
      temp[properties.pop()] = metric;
      metric = temp;
    }
    return metric;
  }
};

@@ -275,22 +275,16 @@
 unction 
-create
 (format,
@@ -296,19 +296,21 @@
 ) %7B%0A    
-var
+const
  formatA
@@ -333,23 +333,27 @@
 lit('.')
-,
+;
 %0A    
- 
+const
  propert
@@ -378,23 +378,25 @@
 slice(0)
-,
+;
 %0A    
- 
+let
  metric 
@@ -436,147 +436,29 @@
 %5D = 
-data.power ?%0A      %7B%0A        power: data.power%0A      %7D%0A      :%0A      %7B%0A        avgpower: data.avgpower,%0A        energy: data.energy%0A      %7D
+this._cleanData(data)
 ;%0A  
@@ -501,11 +501,13 @@
     
-var
+const
  tem
@@ -588,21 +588,199 @@
     
-return metric
+console.log(metric);%0A    return metric;%0A  %7D,%0A%0A  _cleanData: function (data) %7B%0A    const d = %7B%7D;%0A    %5B'power', 'avgpower', 'energy'%5D.filter(p =%3E data%5Bp%5D).map(p =%3E d%5Bp%5D = data%5Bp%5D);%0A    return d
 ;%0A  

Refactor cleaning of data