Yesterday did a group of face test, the request is to n array, find the n number of common sub-arrays.
varA = [7,2,3,4,5];varb = [4,2,3,7,6];varc = [2,3,3,3,7];varD = [4,2,3,8,7];
Above four arrays, with common sub-array 2, 3,7
function Main () { var result = []; var arr = arguments[0]; for (var i=1 ; i<arguments.length; i++) { var arr = arguments[i]. Reduce ((a,item) ={ arr.indexof (item)!=-1 && a.push (item) return a },[]) } return arr}
Concrete methods such as above, ES6 fresh and refined wording, with good reduce can save a lot of things.
The same can be done when the number of elements of an array of the above array should occur;
function Main () { var arr = [].reduce.call (arguments, (a,item) =a.concat (item), []); return arr.reduce (a,num) ={ && ++a[num] | | (a[num]=1); return a },{})}
This reduce has no use of fresh popular AH.
I know everyone in the heart must think of a good fresh force ah.
Yes, learn to reduce the force, other people only shout 666 of the share.
Come on!!!
The common Subarray is drawn from the multiple arrays of reduce, and the number of occurrences of the array elements is counted.