리터럴 값 배열의 다차원 배열을 취하는 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' ]