/**
 * @function getModules
 * @description Get the modules from module names provided
 *
 * @since 4.3.0
 *
 * @param {Array} modules     The modules to filter.
 * @param {Array} moduleNames The module names to filter.
 *
 * @return {object} The modules.
 */
export const getModules = ( modules = [], moduleNames = [] ) => {
	const initialObj = moduleNames.reduce( ( carry, moduleName ) => {
		carry[ moduleName ] = false;
		return carry;
	}, {} );

	return modules.reduce( ( carry, module ) => {
		if ( moduleNames.includes( module.name ) ) {
			return {
				...carry,
				[ module.name ]: module,
			};
		}

		return carry;
	}, initialObj );
};
