Last active
May 24, 2021 18:20
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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