Golfed Linq based check for duplicate array elements
//Given 2 Arrays, Return True if arrays contain common item, else false. //e.g a= ['a','b','g','c'] and b =['z','e','c'] returns true //input : 2 arrays //output: bool using System.Linq;public class Kata{public static bool ContainsCommonItem(char[]a,char[]b)=>a!=null&&b!=null&&a.Intersect(b).Any();}
- //Given 2 Arrays, Return True if arrays contain common item, else false.
- //e.g a= ['a','b','g','c'] and b =['z','e','c'] returns true
- //input : 2 arrays
- //output: bool
using System.Collections.Generic;using System.Linq;public class Kata{public static bool ContainsCommonItem(char[] a, char[] b){if (a==null ||b==null){return false;}for (int i = 0; i < a.Length; i++){for (int j=0; j<b.Length; j++){if (a[i]==b[j]){return true;}}}return false;}}- using System.Linq;public class Kata{public static bool ContainsCommonItem(char[]a,char[]b)=>a!=null&&b!=null&&a.Intersect(b).Any();}