<commit_before>
var getUpdateEnvelopeTableHandler = function(data) {
  var envelopeAudio = data.audio.envelope;
  var envelopeUI = data.ui.envelope;

  var params = envelopeUI.propNames.reduce(function(params, name) {
    timeElement = document.getElementById(name + '-time-cell');
    valueElement = document.getElementById(name + '-value-cell');
    if (timeElement) {
      var timeObj = {
        element: timeElement,
        name: name + 'Time',
      };
      params.push(timeObj);
    }
    if (valueElement) {
      var valueObj = {
        element: valueElement,
        name: name + 'Value',
      };
      params.push(valueObj);
    }
    return params;
  }, []);

  params.forEach(function(param) {
    param.element.addEventListener('change', function() {
      envelopeAudio[param.name] = parseInt(param.element.value, 10)/100;
      data.envelopeChanged = true;
    });
  });

  var updateEnvelopeTable = function() {
    params.forEach(function(param) {
      var value = envelopeAudio[param.name];
      param.element.value = value * 100;
    });
  };

  return updateEnvelopeTable;
};

module.exports = getUpdateEnvelopeTableHandler;<commit_msg>refactor envelope table update code to make it clearer<commit_after>
var getUpdateEnvelopeTableHandler = function(data) {
  var envelopeAudio = data.audio.envelope;
  var envelopeUI = data.ui.envelope;

  var getCellObj = function(cellId, cellName) {
    var cellElement = document.getElementById(cellId);
    var cellObj = { element: cellElement, name: cellName };
    return (cellElement) ? cellObj : null;
  };

  var tableCells = envelopeUI.propNames.reduce(function(cells, name) {
    var timeCell = getCellObj(name + '-time-cell', name + 'Time');
    var valueCell = getCellObj(name + '-value-cell', name + 'Value');
    if (timeCell) {
      cells.push(timeCell);
    }
    if (valueCell) {
      cells.push(valueCell);
    }
    return cells;
  }, []);
  console.log(tableCells);
  tableCells.forEach(function(cell) {
    cell.element.addEventListener('change', function() {
      envelopeAudio[cell.name] = parseInt(cell.element.value, 10)/100;
      data.envelopeChanged = true;
    });
  });

  var updateEnvelopeTable = function() {
    tableCells.forEach(function(cell) {
      var value = envelopeAudio[cell.name];
      cell.element.value = value * 100;
    });
  };

  return updateEnvelopeTable;
};

module.exports = getUpdateEnvelopeTableHandler;
{'fraction_non_alphanumeric': 0.1301482701812191, 'fraction_numerical': 0.006589785831960461, 'mean_word_length': 3.3220640569395017, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5874700', 'n_tokens_mistral': 750, 'n_tokens_neox': 724, 'n_words': 145}