Skip to content

Instantly share code, notes, and snippets.

@tuor4eg
Created April 16, 2018 11:54
Show Gist options
  • Save tuor4eg/367cbe70f78101d995b2a7784cdbf626 to your computer and use it in GitHub Desktop.
Save tuor4eg/367cbe70f78101d995b2a7784cdbf626 to your computer and use it in GitHub Desktop.
export const countSize = (node) => {
return reduce((size, element) => {
if (element.type === 'file') {
return (size + element.meta.size);
}
return size;
}, node, 0);
};
export const sortDu = (array) => array.sort((prev, next) => {
const [name1, size1] = prev;
const [name2, size2] = next;
if (size1 > size2) {
return -1;
}
if (size1 < size2) {
return 1;
}
return 0;
});
export default (tree) => {
const duIt = tree.children.map(element => [element.name, countSize(element)]);
return sortDu(duIt);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment