我们需要编写一个JavaScript函数,该函数接受文字值数组的多维数组。我们的函数应该返回输入数组中所有子数组的相交数组。
为此的代码将是-
const arr = [ ["garden","canons","philips","universal"], ["universal","ola","uber","bangalore"] ]; const findMultiIntersection = (arr = []) => { const res = []; arr.forEach(el => { const thisObj = this; el.forEach(element => { if(!thisObj[element]){ thisObj[element] = true; } else{ res.push(element) }; }); }, {}); return res; }; console.log(findMultiIntersection(arr));
输出结果
控制台中的输出将是-
[ 'universal' ]