Skip to content

Instantly share code, notes, and snippets.

@RodrigoNovais
Last active May 24, 2021 18:20
Show Gist options
  • Save RodrigoNovais/d4912655d34324ed5280efc4746c4d72 to your computer and use it in GitHub Desktop.
Save RodrigoNovais/d4912655d34324ed5280efc4746c4d72 to your computer and use it in GitHub Desktop.
Returns the values from array that are present in each of the other arrays
/**
* Returns the values from array that are present in each of the other arrays
*
* @param {...unknown[]} arrays
* @returns {unknown[]}
*/
export const intersection = (...arrays: unknown[]): unknown[] => {
return arrays.reduce((a, b) => a.filter((c: any) => b.includes(c)))
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment