js07.md 1.7 KB

Таблица умножения

http://homework.pavelefimen95.fe.a-level.com.ua/js07/MultiplytTable1-files

Подсветить ячейку

http://homework.pavelefimen95.fe.a-level.com.ua/js07/MultiplytTable2-files

Подсветить строку и столбец

http://homework.pavelefimen95.fe.a-level.com.ua/js07/MultiplytTable3-files

makeProfileTimer

function doSomething(){
	return 2 + 2;
}
var timer = makeProfileTimer(doSomething)

function makeProfileTimer(doSomething){
	var t1 = performance.now();
	doSomething();
	var t2 = performance.now();
	return function(){
		return t2 - t1;
	}
	
}

alert(timer());

makeSaver

function makeSaver(rand){
	var res = rand();
	return function(){
		return res;
	}
}
var saver = makeSaver(Math.random);
var value1 = saver();
var value2 = saver();

console.log(value1);
console.log(value2);

console.log(value1 === value2);

Final Countdown

var counter = (function(){
	var i = 5;
	return function(){
		
		if(i === 0)
			console.log("Поехали!");
		else{
			console.log(i--);
			again();
		}
	}
})();
function again(){
	setTimeout(counter, 1000);
}
again();

myBind

function myBind(func,object,arr){
	return function(val){
		if(arr[0] === undefined)
			arr[0] = val;
		return func.apply(object,arr);
	}
}
var pow5 = myBind(Math.pow, Math, [undefined, 5]); 
var cube = myBind(Math.pow, Math, [undefined, 3]); 
console.log(pow5(2)); 
console.log(cube(3)); 

var zeroPrompt = myBind(prompt, window, [undefined, "0"]);
                                                          
var someNumber = zeroPrompt("Введите число");              
console.log(someNumber);