Skip to content

Commit

Permalink
Add JSDoc arrayDiff (#26)
Browse files Browse the repository at this point in the history
Add description JSDoc to `arrayDiff` for clarification and avoiding misinterpretations of its purpose and result.
  • Loading branch information
maxiskell authored Mar 4, 2025
1 parent 72e5564 commit acebba1
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/helpers/arrayDiff.ts
Original file line number Diff line number Diff line change
@@ -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))),
);
};

0 comments on commit acebba1

Please sign in to comment.