-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlearnCode.html
More file actions
52 lines (46 loc) · 993 Bytes
/
learnCode.html
File metadata and controls
52 lines (46 loc) · 993 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<html>
<head>
<title>Leet Code Practice </title>
</head>
<body>
<h1>Leet Code</h1>
<script>
//2620
//https://leetcode.com/problems/counter/
//Given an integer n, return a counter function. This counter function
//initially returns n and then returns 1 more than the previous value every subsequent time it is called (n, n + 1, n + 2, etc).
/**
* @param {number} n
* @return {Function} counter
*/
var i;
var cnt =0;
var output = [];
var createCounter = function(n) {
output[0] = n;
console.log(output);
for(i=1;i<calles.length;i++){
if(calles[i] === 'call'){
n = n+1;
output[i] = n;
console.log(output);
}
}
// return output;
return function() {
return output;
};
};
var n = 10;
var calles = ["call","call","call"];
createCounter(n);
//var counter = createCounter(n);
/**
* const counter = createCounter(10)
* counter() // 10
* counter() // 11
* counter() // 12
*/
</script>
</body>
</html>