Find the Difference of Two Arrays

Easy
119
6
48.3% Acceptance

In this lab, you have to implement a function findDifference that will take two 0-indexed integer arrays nums1 and nums2. You should return a list answer of size 2 where:

  • answer[0] is a list of all distinct integers in nums1 which are not present in nums2.
  • answer[1] is a list of all distinct integers in nums2 which are not present in nums1.

The integers in the lists may be returned in any order.

Examples

Here are some examples of the findDifference function:

findDifference([1,2,3], [2,4,6]); // Output: [[1,3],[4,6]] findDifference([1,2,3,3], [1,1,2,2]); // Output: [[3],[]]

Explanation

  • For the first example, 2 is present in both arrays but 1 and 3 are not present in nums2, so answer[0] is [1,3]; Similarly, 4 and 6 are not present in nums1, so answer[1] is [4,6].
  • For the second example, 1 and 2 are present in both arrays, but 3 is not present in nums2 so answer[0] is [3]; All integers in nums2 are present in nums1, so answer[1] is [].

Constraints

  • 1 <= nums1.length, nums2.length <= 1000
  • -1000 <= nums1[i], nums2[i] <= 1000

Challenges

In order to successfully complete this lab, you must pass the following challenges:

  1. Implement the findDifference function and make sure it returns the correct difference between the two arrays nums1 and nums2.
  2. Export the findDifference function using the ESM export syntax.