Skip to content

Commit ac8cfe2

Browse files
committed
Promise BTS added in detail
1 parent 647357e commit ac8cfe2

File tree

7 files changed

+87
-4
lines changed

7 files changed

+87
-4
lines changed

.DS_Store

0 Bytes
Binary file not shown.

C/closure/readme.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,10 @@ closureFun(20);
7373

7474
6. Can closures be used with event handlers?
7575

76-
Yes, closures are often used in event handlers to remember and manage state related to the event, even after the event has been triggered.
76+
Yes, closures are often used in event handlers to remember and manage state related to the event, even after the event has been triggered.
77+
78+
79+
80+
### Links
81+
82+
- Closures BTS(https://www.youtube.com/watch?v=6Ixyltr8_R0&t=22s)

P/promises/README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Promise
22

33
Promise is an object which represents the eventual completion (or failure) of an Asynchronous operation.
4+
##### Components
5+
- Promise Constructor
6+
- Executor Function
47
```
58
const p = new Promise((res , rej)=> {
69
@@ -71,4 +74,11 @@ When you use await, the function pauses execution until the awaited promise reso
7174
.then() .catch()
7275

7376
2. What is the difference between `Promise` and `Async-Await`?
74-
77+
78+
79+
80+
81+
#### Learning Material
82+
83+
- [Understanding internal working of Promises using GIFs [ Video ]](https://www.youtube.com/watch?v=Xs1EMmBLpn4)
84+
- [GIF blog on Promises understanding](https://web.archive.org/web/20230325052017/https://dev.to/lydiahallie/javascript-visualized-promises-async-await-5gke)

gfg/wave_array.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
sort the array such that it becomes a wave
3+
*/
4+
5+
function convertToWave(arr) {
6+
let n = arr.length;
7+
8+
for (let i = 0; i < n - 1; i++) {
9+
const element = arr[i];
10+
const nextElement = arr[i + 1];
11+
// even index
12+
if (i % 2 === 0 && element < nextElement) {
13+
14+
//swap
15+
let temp1 = arr[i];
16+
arr[i] = arr[i+1];
17+
arr[i+1]= temp1;
18+
19+
}
20+
// odd index
21+
else if (i % 2 !== 0 && element > nextElement) {
22+
//swap
23+
let temp2 = arr[i];
24+
arr[i] = arr[i + 1];
25+
arr[i + 1] = temp2;
26+
}
27+
}
28+
29+
console.log(arr);
30+
31+
}
32+
33+
34+
convertToWave([1, 2 ,3 ,4 ,5]);

index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313

14-
<script src="./leetcode-solutions/189-Rotate_Array.js"> </script>
14+
<script src="./leetcode-solutions/66-plus_one.js"> </script>
1515
</body>
1616

1717
</html>

leetcode-solutions/66-plus_one.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
You are given a large integer represented as an integer array digits, where each digits[i] is the ith digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading 0's.
3+
4+
Increment the large integer by one and return the resulting array of digits
5+
*/
6+
7+
var plusOne = function (digits) {
8+
9+
let carry = false;
10+
for (let i = digits.length-1; i >=0 ; i--) {
11+
12+
if(digits[i] !== 9){
13+
digits[i] = digits[i] + 1;
14+
carry = false;
15+
return digits;
16+
} else{
17+
carry = true;
18+
digits[i] = 0;
19+
}
20+
21+
}
22+
if(carry){
23+
digits.unshift(1);
24+
}
25+
return digits;
26+
};
27+
28+
29+
let digits1 = [1, 9, 9];
30+
console.log(plusOne(digits1));
31+

links.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# Important Links
22

3-
- [Practice Javascript Logic](http://teachertrek.in/#/js-logic-building)
3+
- [Practice Javascript Logic](http://teachertrek.in/#/js-logic-building)
4+
- [Javascript Visualised](https://www.youtube.com/@theavocoder/videos)
5+
- [Javascript concepts by GIFs](https://www.linkedin.com/feed/update/urn:li:activity:7300416805972389889/)

0 commit comments

Comments
 (0)