Skip to content

Instantly share code, notes, and snippets.

@tuor4eg
Created April 19, 2018 14:21
Show Gist options
  • Save tuor4eg/74a4e90808634d5000fc31c74ce7f5bb to your computer and use it in GitHub Desktop.
Save tuor4eg/74a4e90808634d5000fc31c74ce7f5bb to your computer and use it in GitHub Desktop.
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 default (obj) => Array.from(new Set(sortDeps(Object.keys(obj), obj)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment