Selaa lähdekoodia

Заиыкание переделано

Vladislav342 2 vuotta sitten
vanhempi
commit
07d098cd4d
1 muutettua tiedostoa jossa 26 lisäystä ja 13 poistoa
  1. 26 13
      HW_09/index.html

+ 26 - 13
HW_09/index.html

@@ -9,25 +9,27 @@
 	<script>
 	
 //---------makeProfileTimer
-		/*function makeProfileTimer(){
+		function makeProfileTimer(){
 			let time1=performance.now();
 			return function(){
 				let time2=performance.now();
-				alert(time2-time1);
+				return time2-time1;
+				//alert(time2-time1);
 			}
 		}
 
-		function fib(n){
+		/*function fib(n){
 			if(n==1||n==2){
 				return 1;
 			}else{
 				return fib(n-1)+fib(n-2);
 			}
-		}
+		}*/
 		
 		var timer=makeProfileTimer();
-		alert(fib(10));
-		timer();*/
+		alert('Замеряем время работы этого alert');
+		//alert(fib(10));
+		alert(timer());
 
 //-----------makeSaver
 		function makeSaver(fn){
@@ -56,24 +58,35 @@
     	alert(`Слушай, ${nameSaver()}, го пить пиво. Ведь prompt был только один раз`)
 
 //-----------Final Countdown
-		/*(function count(){
+		(function count(){
 			let x=5;
 			let y=setInterval(function(){
 				console.log(x);
 				if(x==1){
-					console.log('поехали');
 					clearInterval(y);
+					console.log('поехали');
 				}
 				x--;
 			},1000)
-		})();*/
+		})();
 
 //------------myBind
-		/*function myBind(fn,context,args){
-			return function(){
+		function myBind(fn,context,args){
+			/*return function(){
 				let args2=Object.assign(args,arguments);
 				return fn.call(context,...args2);
+			}*/
+			let arr=[...args];
+			return function(){
+				let arr2=Array.from(arguments);
+				for(let i=0;i<arr.length;i++){
+					if(!arr[i]){
+						arr[i]=arr2.shift();
+					}
+				}
+				return fn.call(context,...arr);
 			}
+  		
 		}
 
 		var pow5 = myBind(Math.pow, Math, [undefined, 5]);
@@ -82,7 +95,7 @@
 		console.log(cube(3));   //27
 
 		var chessMin = myBind(Math.min, Math, [undefined, 4, undefined, 5,undefined, 8,undefined, 9]);
-		console.log(chessMin(-1,-5,3,15)); //NaN ???
+		console.log(chessMin(-1,-5,3,15));  //-5
 
 		var zeroPrompt = myBind(prompt, window, [undefined, "0"]);
 
@@ -90,7 +103,7 @@
 		console.log(someNumber);
 
 
-		console.log(myBind((...params) => params.join(''), null, [undefined, 'b', undefined, undefined, 'e', 'f'])('a','c','d') === 'abcdef');*/
+		console.log(myBind((...params) => params.join(''), null, [undefined, 'b', undefined, undefined, 'e', 'f'])('a','c','d') === 'abcdef');  //true
 	</script>
 </body>
 </html>