/** * function to convert array to string and string to array * @param {*} input * @param {String} separator * @returns {*} */ function convertArrayAndString(input, separator = ', ') { // If the separator is just a comma without a space, change it to ", " if (separator === ',') { separator = ', ' } if (Array.isArray(input)) { // Convert array to string with the correct separator return input.join(separator) } else if (typeof input === 'string') { // Convert string to array using the separator return input.split(separator) } else { throw new Error('Input must be either an array or a string.') } } module.exports = { convertArrayAndString }