Skip to content

Instantly share code, notes, and snippets.

@IOIO72
Created May 10, 2019 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IOIO72/ba62b2301a83b8d042030e910224f318 to your computer and use it in GitHub Desktop.
Save IOIO72/ba62b2301a83b8d042030e910224f318 to your computer and use it in GitHub Desktop.
Joins two arrays and returns this array or returns a string when the array contains one single value
const joinToArrayOrGetString = (strOrArray1, strOrArray2) => {
const ret = [...convertToArray(strOrArray1), ...convertToArray(strOrArray2)].filter(item => typeof item === 'string');
return (ret.length === 1) ? ret[0] : ret;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment