
export const filterChildPermissionsByType : Function = (permissions : Object[]) => {
	return permissions.map(parent => ({
	  ...parent,
	  childs: parent.childs ? filterOutPermissionsOfCertainType(parent.childs, 1) : undefined,
	}));
}

export const filterOutPermissionsOfCertainType : Function = (permissions : Object[], excludeType : number) => {
	return permissions.filter(permission => permission.p_type !== excludeType)
	  .map(child => ({
	    ...child,
	    childs: child.childs ? filterOutPermissionsOfCertainType(child.childs, excludeType) : undefined,
	  }));
}



export const findidx : Function = (arr : any, val : any) => {
	return arr.findIndex(item => {
		return item.id === val
	})
}

export const intersectionAlike : Function = (objA : any, objB : any) => {
	const result = {};
	for (const keyA in objA) {
		if (objB.hasOwnProperty(keyA)) {
			result[keyA] = objB[keyA];
		}
	}
	return result;
}



export const hasValue : Function = (obj : any) => {
	let result = '';
	result = Object.keys(obj).filter(key => obj[key] !== 0).map(key => `${obj[key]}`).join('')
	return result;
}


export const divObj : Function = (obj : any) => {
	const result = []
	obj.reduce((acc, curr, index) => {
		curr.idx = index;
		result.push(curr)
		// const key = `node${index}Info`;
		// acc[key] = curr;
		// return acc;
	}, {});

	return result;
}



export const alreadyValue : Function = (obj : any) => {
	const result = []
	obj.reduce((acc, curr, index) => {
		curr.idx = index;
		result.push(curr)
		// const key = `node${index}Info`;
		// acc[key] = curr;
		// return acc;
	}, {});

	return result;
}