<commit_before>export default class FlatMetaData {
  static to(data) {
    return buildMetaData(data);
  }
}

function buildMetaData(all) {
  const items = buildItems(extractAllItems(all));
  return {items: items};
}

function extractAllItems(all) {
  const groups = all.groups;
  let extractedItems = {};
  for (let groupName in groups) {
    extractItemsFromGroup(groups, groupName, extractedItems);
  }
  return extractedItems;
}

function extractItemsFromGroup(groups, groupName, addItemsTo) {
  const items = groups[groupName].items;
  for (let key in items) {
    const item = cloneObject(items[key]);
    item.groupName = groupName;
    addItemsTo[key] = item;
  }
}

const toInt = (string) => Number.parseInt(string, 10); 
function buildItems(flattenedItems) {
  const items = [];
  const ids = Object.keys(flattenedItems).map(toInt);
  const sortedIds = ids.sort((id1, id2) => id1 - id2);
  for (let id of sortedIds) {
    let item = flattenedItems[id];
    item.id = id;
    items.push(item);
  }
  return items;
}

function cloneObject(obj) {
  return JSON.parse(JSON.stringify(obj));
}
<commit_msg>Move the clone function closer to it's usage.<commit_after>export default class FlatMetaData {
  static to(data) {
    return buildMetaData(data);
  }
}

function buildMetaData(all) {
  const items = buildItems(extractAllItems(all));
  return {items: items};
}

function extractAllItems(all) {
  const groups = all.groups;
  let extractedItems = {};
  for (let groupName in groups) {
    extractItemsFromGroup(groups, groupName, extractedItems);
  }
  return extractedItems;
}

const cloneObject = (obj) => JSON.parse(JSON.stringify(obj));
function extractItemsFromGroup(groups, groupName, addItemsTo) {
  const items = groups[groupName].items;
  for (let key in items) {
    const item = cloneObject(items[key]);
    item.groupName = groupName;
    addItemsTo[key] = item;
  }
}

const toInt = (string) => Number.parseInt(string, 10); 
function buildItems(flattenedItems) {
  const items = [];
  const ids = Object.keys(flattenedItems).map(toInt);
  const sortedIds = ids.sort((id1, id2) => id1 - id2);
  for (let id of sortedIds) {
    let item = flattenedItems[id];
    item.id = id;
    items.push(item);
  }
  return items;
}


{'fraction_non_alphanumeric': 0.12533452274754683, 'fraction_numerical': 0.0053523639607493305, 'mean_word_length': 4.180138568129331, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '6509394', 'n_tokens_mistral': 734, 'n_tokens_neox': 729, 'n_words': 181}