From acebba167ac421b3d649b2134b11f9fb5ca2b96d Mon Sep 17 00:00:00 2001 From: maxi Date: Tue, 4 Mar 2025 12:04:40 +0000 Subject: [PATCH] Add JSDoc `arrayDiff` (#26) Add description JSDoc to `arrayDiff` for clarification and avoiding misinterpretations of its purpose and result. --- src/helpers/arrayDiff.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/helpers/arrayDiff.ts b/src/helpers/arrayDiff.ts index 7aa4940..5fa8e11 100644 --- a/src/helpers/arrayDiff.ts +++ b/src/helpers/arrayDiff.ts @@ -1,10 +1,13 @@ import { uniqueValues } from "./uniqueValues"; -// TODO: optimize with maps? +/** + * Given 2 arrays, returns the elements that belong to each but not both at the same time. + */ export const arrayDiff = (arr1: any[], arr2: any[]) => { + // TODO: optimize with maps? return uniqueValues( arr1 .filter((value) => !arr2.includes(value)) - .concat(arr2.filter((value) => !arr1.includes(value))) + .concat(arr2.filter((value) => !arr1.includes(value))), ); };