re: Daily Coding Puzzles - Nov 4th - Nov 9th VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Wednesday Array.diff (6 KYU): Your goal in this kata is to implement a difference function, which subtracts one list from another and returns th...
 

It wasn't as easy as doing a set difference as the a needed to keep the duplicate values.

Below is the answer in C#.

Where is the same as filter in JavaScript.

using System.Linq;
using System.Collections.Generic;

public class Kata
{
  public static int[] ArrayDiff(int[] a, int[] b)
  {
    var hash = new HashSet<int>(b);
    return a.Where(_ => !hash.Contains(_)).ToArray();
  }
}
code of conduct - report abuse