Hack Frontend Community

Array Difference

Sber
You need to write a function difference(arr1, arr2) that takes two arrays of numbers arr1 and arr2. The function should return an array containing elements from arr1 that are not in arr2. Conditions:
  • - Each array contains only numbers.
  • - Arrays can be empty.
  • - The order of elements in the returned array should match their order in arr1.

Examples:

Input 1: [5, 6, 7], [7, 8, 9]
Output 1: [5, 6]
Input 2: [1, 4, 3, 2], [1, 2]
Output 2: [4, 3]
Run your code to see results.