<commit_before>import { isNil, isArray, pick } from 'lodash';

function traverseTree(originParent, originChild, clonedParent, syncedProfile) {
  if (!isArray(clonedParent.children)) {
    clonedParent.children = [];
  }
  const clonedChild = pick(originChild, ['dateAdded', 'url', 'title', 'parentId']);
  clonedChild.type = !isNil(originChild.url) ? 'file' : 'folder';
  clonedChild.syncedTo = { [syncedProfile]: true };
  clonedParent.children.push(clonedChild);
  if (isArray(originChild.children) && originChild.children.length > 0) {
    originChild.children.forEach(originGrandChild => {
      traverseTree(originChild, originGrandChild, clonedChild, syncedProfile);
    });
  }
}

export function mapToStdOutput(fullChromeBookmarkTree, syncedProfile) {
  const chromeTree = fullChromeBookmarkTree[0];
  const stdTree = pick(chromeTree, ['dateAdded']);
  chromeTree.children.forEach(child => {
    traverseTree(chromeTree, child, stdTree, syncedProfile);
  });
  return stdTree.children;
}<commit_msg>[REFACTOR] changed mapToStdOutput function to utilize reduce<commit_after>import { isNil, pick } from 'lodash';

export function mapToStdOutput(treeNode, syncedProfile, fullIndex) {
  return treeNode.reduce((acc, element, index) => {
    const element0 = pick(element, ['dateAdded', 'url', 'title', 'parentId']);
    element0.folder = isNil(element.url);
    element0.syncedTo = { [syncedProfile]: true };
    element0.index = isNil(fullIndex) ? `${index}` : `${fullIndex}.${index}`;
    if (element0.folder) {
      element0.children = mapToStdOutput(element.children, syncedProfile, element.index);
    }
    acc.push(element0);
    return acc;
  }, []);
}
{'fraction_non_alphanumeric': 0.14414414414414414, 'fraction_numerical': 0.005405405405405406, 'mean_word_length': 5.239700374531835, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '1272882', 'n_tokens_mistral': 528, 'n_tokens_neox': 520, 'n_words': 101}