server/variables/sync/intersection.js
function compute2(a,b){
	if(!a || !b) return []
	if(a.length > b.length){
		var t = b
		b = a
		a = t
	}
	
	if(a.length === 0) return []
	if(a.length === 1){
		if(b.indexOf(a[0]) === -1){
			return []
		}else{
			return a
		}
	}
	
	var ma = {}
	for(var j=0;j<a.length;++j){
		ma[a[j]] = true
	}
	
	var result = []
	for(var j=0;j<b.length;++j){
		var v = b[j]
		if(ma[v]){
			result.push(v)
		}
	}
	//console.log('intersection ' + JSON.stringify([a,b,result]))
	
	//console.log('*big intersection of ' + JSON.stringify(_.map([a,b], function(p){return p.length})) + ' -> ' + result.length + ' (' + typeof(a[0]||b[0]) + ')')
	return result
}
function compute2(a,b){
	if(!a || !b) return []
	if(a.length > b.length){
		var t = b
		b = a
		a = t
	}
	
	if(a.length === 0) return []
	if(a.length === 1){
		if(b.indexOf(a[0]) === -1){
			return []
		}else{
			return a
		}
	}
	
	var ma = {}
	for(var j=0;j<a.length;++j){
		ma[a[j]] = true
	}
	
	var result = []
	for(var j=0;j<b.length;++j){
		var v = b[j]
		if(ma[v]){
			result.push(v)
		}
	}
	//console.log('intersection ' + JSON.stringify([a,b,result]))
	
	//console.log('*big intersection of ' + JSON.stringify(_.map([a,b], function(p){return p.length})) + ' -> ' + result.length + ' (' + typeof(a[0]||b[0]) + ')')
	return result
}
/*
var intersections = 0
setInterval(function(){
console.log('intersections: ' + intersections)
},1000)