var intersection = function (nums) { const map = {} const l = nums.length nums.forEach(item => { item.forEach(c => { if (!map[c]) { map[c] = 1 } else { map[c]++ } }) }) return Object.entries(map).filter(item => item[1] === l).map(item => item[0]).sort((a, b) => a - b) }; console.log(intersection([[3,1,2,4,5],[1,2,3,4],[3,4,5,6]]))