Skip to content

Instantly share code, notes, and snippets.

export const sortDeps = (keys, packetList) => {
const keyRed = keys.reduce((acc, element) => {
if (packetList[element] instanceof Array && packetList[element].length === 0 || !packetList[element]) {
return [...acc, element];
}
return [...acc, ...sortDeps(packetList[element], packetList), element];
}, []);
return keyRed;
};
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) => {
export const findFile = (node, fn, pathToFile) => {
const pathElement = node.name;
if (node.type === 'directory') {
return node.children.reduce((res, element) => [...res, ...findFile(element, fn, path.join(pathToFile, pathElement))], []);
}
if (fn(node)) {
return [path.join(pathToFile, node.name)];
}
return [];
};
class Enumerable {
constructor(collection, operations) {
this.collection = collection;
this.operations = operations || [];
}
build(fn) {
return new Enumerable(this.collection.slice(), this.operations.concat(fn));
}