js/partition.js
/**
 * Size of the intersection of two sorted lists of data
 **/
Size of the intersection of two sorted lists of data
Size of the intersection of two sorted lists of data
function countIntersection(a,b) {
	let count = 0;
	if(a.length == 0 || b.length == 0)
		return count;
	let bIndex = 0;
	let aIndex = 0;
	let nextA = a[aIndex].id;
	let nextB = b[bIndex].id;
	while(aIndex < a.length && bIndex < b.length) {
		while(bIndex < b.length && b[bIndex].id < nextA)
			bIndex++;
		if(bIndex == b.length) break;
		nextB = b[bIndex].id;
		while(aIndex < a.length && a[aIndex].id < nextB)
			aIndex++;
		if(aIndex == a.length) break;
		nextA = a[aIndex].id;
		if(nextA == nextB) {
			count++;
			aIndex++;
			bIndex++;
		}
	}
	return count;
}
function countIntersection ( a , b ) { let count = 0 ; if ( a . length == 0 || b . length == 0 ) return count ; let bIndex = 0 ; let aIndex = 0 ; let nextA = a [ aIndex ] . id ; let nextB = b [ bIndex ] . id ; while ( aIndex < a . length && bIndex < b . length ) { while ( bIndex < b . length && b [ bIndex ] . id < nextA ) bIndex ++ ; if ( bIndex == b . length ) break ; nextB = b [ bIndex ] . id ; while ( aIndex < a . length && a [ aIndex ] . id < nextB ) aIndex ++ ; if ( aIndex == a . length ) break ; nextA = a [ aIndex ] . id ; if ( nextA == nextB ) { count ++ ; aIndex ++ ; bIndex ++ ; } } return count ; }
Size of the intersection of two sorted lists of data
Size of the intersection of two sorted lists of data