Skip to content

Commit d8d62ee

Browse files
playground code updated and 1 recursion program added
1 parent 052ff07 commit d8d62ee

File tree

3 files changed

+55
-15
lines changed

3 files changed

+55
-15
lines changed

Recursion/numbers-between-low-high.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// At Concentrix R1
2+
var a = [1, [2, [3, 4], [10, 7], 5], [9]]
3+
4+
const findNumbers = (inputArr, low, high) => {
5+
// const betweenNums = new Set();
6+
const betweenNumsArr = [];
7+
8+
for (let i = 0; i < inputArr.length; i++) {
9+
const ele = inputArr[i]
10+
if (Array.isArray(ele)) {
11+
betweenNumsArr.push(...findNumbers(ele, low, high))
12+
} else {
13+
if (ele >= low && ele <= high) {
14+
betweenNumsArr.push(ele)
15+
}
16+
}
17+
}
18+
19+
return betweenNumsArr;
20+
21+
}
22+
23+
console.log(findNumbers(a, 5, 12))

Test-Self/playground.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
const obj = {
2-
a: 10,
3-
b: function () {
4-
console.log(this.a);
5-
const inner = () => {
6-
console.log(this.a);
7-
};
8-
inner();
9-
},
10-
};
11-
12-
const b = obj.b;
13-
b(); // Output?
14-
obj.b(); // Output?
15-
1+
// const obj = {
2+
// a: 10,
3+
// b: function () {
4+
// console.log(this.a);
5+
// const inner = () => {
6+
// console.log(this.a);
7+
// };
8+
// inner();
9+
// },
10+
// };
11+
12+
// const b = obj.b;
13+
// b(); // Output?
14+
// obj.b(); // Output?
15+
16+
console.log(typeof null, typeof undefined, typeof NaN)

Test-Self/playground.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,19 @@ const highestBirthdayCandleCounts = (inputArr: number[]): number => {
192192
// console.log(highestBirthdayCandleCounts([4,4,1,3]));
193193

194194
console.info(`----- Multiple Pointers ------`)
195+
196+
const isSubsequence = (str1: string, str2: string): boolean => {
197+
if(str1.length === 0 || str2.length === 0) return false;
198+
let i: number = 0, j: number = 0;
199+
while(j < str2.length) {
200+
if(str1[i] === str2[j]) i++;
201+
if(i === str1.length) return true;
202+
j++;
203+
}
204+
return false
205+
}
206+
207+
console.log(isSubsequence('hello', 'hello world')); // true
208+
console.log(isSubsequence('sing', 'sting')); // true
209+
console.log(isSubsequence('abc', 'abracadabra')); // true
210+
console.log(isSubsequence('abc', 'acb')); // false (order matters)

0 commit comments

Comments
 (0)