Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function systemRegister(args) {
- const obj = [];
- args.forEach((element) => {
- const [systemName] = element.trim().split('|');
- const systemObj = {};
- systemObj.system = systemName;
- systemObj.value = [];
- const dub = obj.filter((item) => item.system.localeCompare(systemName) === 0).length;
- if (dub === 0) {
- obj.push(systemObj);
- }
- });
- args.forEach((element) => {
- const [systemName, componentName] = element.trim().split('|');
- obj.forEach((el) => {
- const componentObj = {};
- componentObj.component = componentName;
- componentObj.value = [];
- const dubComponent = el.value.filter((item) => item.component.localeCompare(componentName) === 0).length;
- if (el.system.localeCompare(systemName) === 0) {
- if (dubComponent === 0) {
- el.value.push(componentObj);
- }
- }
- });
- });
- args.forEach((element) => {
- const [systemName, componentName, subcomponentName] = element.trim().split('|');
- obj.forEach((el) => {
- el.value.forEach((item) => {
- const dubSubComponent = item.value.filter((subComponent) => subComponent.localeCompare(subcomponentName) === 0).length;
- if (item.component.localeCompare(componentName) === 0) {
- if (dubSubComponent === 0) {
- item.value.push(subcomponentName);
- }
- }
- });
- const componentObj = {};
- componentObj.component = componentName;
- componentObj.value = [];
- const dubComponent = el.value.filter((item) => item.component.localeCompare(componentName) === 0).length;
- if (el.system.localeCompare(systemName) === 0) {
- if (dubComponent === 0) {
- el.value.push(componentObj);
- }
- }
- });
- });
- obj.sort((a, b) => a.value.length - b.value.length || a.system.localeCompare(b.sytem));
- obj.reverse();
- obj.forEach((element) => {
- console.log(element.system);
- element.value.sort((a, b) => b.value.length - a.value.length);
- element.value.forEach((item) => {
- console.log(`|||${item.component.trimStart()}`);
- item.value.forEach((sub) => {
- console.log(`||||||${sub.trimStart()}`);
- });
- });
- });
- }
Add Comment
Please, Sign In to add comment