Binary Search Tree

var obj = {};

function fun(){
	var min = 1;
	var max = 1000000;
	var guess;
	var number = Math.floor(Math.random() * max) + min;
	var counter = 0;
	
	while (guess !== number){
	        counter += 1;
		guess = Math.floor((min + max) / 2);
		if (number > guess){
			min = guess + 1;
		} else if (number < guess) {
			max = guess - 1;
		}
	}
	if ( !obj[counter] ){
		obj[counter] = 1;
	} else {
		obj[counter] += 1;
	}
}
for (var x = 0; x < 10000; x++){
	fun();
}
console.log(obj)