From df2d2337bf3e8d289c726735dade1cfa3a6904b7 Mon Sep 17 00:00:00 2001
From: Lakshman
Date: Sun, 3 May 2020 23:54:16 +0600
Subject: [PATCH 01/56] Create outputGuess.js
---
01 - JavaScript-Basics/outputGuess.js | 89 +++++++++++++++++++++++++++
1 file changed, 89 insertions(+)
create mode 100644 01 - JavaScript-Basics/outputGuess.js
diff --git a/01 - JavaScript-Basics/outputGuess.js b/01 - JavaScript-Basics/outputGuess.js
new file mode 100644
index 0000000..ebd7f00
--- /dev/null
+++ b/01 - JavaScript-Basics/outputGuess.js
@@ -0,0 +1,89 @@
+'use strict';
+function logThis() {
+ this.desc = 'logger';
+ console.log(this); // { desc: 'logger' }
+}
+
+new logThis();
+
+// '''''''''''''''''''''''''''''
+var Storm = function () {};
+Storm.prototype.precip = 'rain';
+var WinterStorm = function () {};
+WinterStorm.prototype = new Storm();
+WinterStorm.prototype.precip = 'snow';
+var bob = new WinterStorm();
+console.log(bob.precip); // snow
+
+// lllllllllllllllllllllllllllllll
+const obj = {
+ a: 1,
+ b: 2,
+ c: 3,
+};
+
+const obj2 = {
+ ...obj,
+ a: 0,
+};
+
+console.log(obj2.a, obj2.b); // 0 2
+
+// llllllllllllllllllllllllllll
+console.log(sum(10, 20)); // 30 ReferenceError
+// console.log(diff(10, 20));
+ function sum(x, y) {
+ return x + y;
+ }
+ let diff = function(x, y) {
+ return x - y;
+ }
+
+
+
+// lllllllllllllllllllllll
+function sayHello() {
+ console.log("hello");
+}
+
+var func = sayHello;
+func.answer = 42;
+
+console.log(sayHello.answer); // 42
+
+
+var a = ['dog', 'cat', 'hen'];
+a[100] = 'fox';
+
+console.log(a.length);
+
+var a;
+var b = (a=3) ? true: false
+
+let arr = [];
+
+console.log(arr);
+console.log([] ==[]);
+
+class X {
+ get Y() {return 42;}
+}
+
+
+var x = new X();
+
+console.log(x.Y);
+
+
+
+var v = 1;
+var f1 = function () {
+ console.log(v);
+}
+
+var f2 = function () {
+ var v = 2;
+ f1();
+}
+
+f2();
From 77fc917a9f76c75306d51cde8a11b6e1f637453f Mon Sep 17 00:00:00 2001
From: lgope
Date: 2020年7月18日 23:52:58 +0600
Subject: [PATCH 02/56] =?UTF-8?q?todays=20day=20name=20in=207=20days=20?=
=?UTF-8?q?=F0=9F=91=8D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
01 - JavaScript-Basics/getTodayName.js | 5 +++++
1 file changed, 5 insertions(+)
create mode 100644 01 - JavaScript-Basics/getTodayName.js
diff --git a/01 - JavaScript-Basics/getTodayName.js b/01 - JavaScript-Basics/getTodayName.js
new file mode 100644
index 0000000..bf8d402
--- /dev/null
+++ b/01 - JavaScript-Basics/getTodayName.js
@@ -0,0 +1,5 @@
+const weekdays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
+// todays day
+const day = weekdays[new Date().getDay()];
+
+console.log(day);
\ No newline at end of file
From 8e46e41e02ee719be77d8fa7f82c33f335942c54 Mon Sep 17 00:00:00 2001
From: lgope
Date: 2020年8月26日 20:36:37 +0600
Subject: [PATCH 03/56] =?UTF-8?q?recursive=20function=20practice=20?=
=?UTF-8?q?=F0=9F=94=83?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../recursiveFunction.js | 45 +++++++++++++++++++
1 file changed, 45 insertions(+)
create mode 100644 05 - Objects-And-Functions/recursiveFunction.js
diff --git a/05 - Objects-And-Functions/recursiveFunction.js b/05 - Objects-And-Functions/recursiveFunction.js
new file mode 100644
index 0000000..46c3f30
--- /dev/null
+++ b/05 - Objects-And-Functions/recursiveFunction.js
@@ -0,0 +1,45 @@
+// 1
+function countFuction(num) {
+ console.log(num);
+ if (num <= 0) { + return; + } + + countFuction(num - 1); +} + +countFuction(8); + +// 2 +function anotherAountFuction(num) { + console.log(num); + if (num> 0) {
+ anotherAountFuction(num - 1);
+ }
+}
+
+anotherAountFuction(8);
+
+// sum of digits
+function sumOfDigits(num) {
+ if (num == 0) {
+ return 0;
+ }
+ return (num % 10) + sumOfDigits(Math.floor(num / 10));
+}
+
+let sum = sumOfDigits(324);
+console.log(`res = ${sum}`);
+
+// factorial
+var factorial = function (number) {
+ // break condition
+ if (number <= 0) { + return 1; + } + + // block to execute + return number * factorial(number - 1); +}; + +console.log(`Factorial = ${factorial(9)}`); From e6fed13de3bf9c089dc3e4a296ae4f468aa8c888 Mon Sep 17 00:00:00 2001 From: lgope
Date: 2020年8月27日 23:29:53 +0600
Subject: [PATCH 04/56] recursive binary search in js
---
algorithms/binarySearchRecursive.js | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
create mode 100644 algorithms/binarySearchRecursive.js
diff --git a/algorithms/binarySearchRecursive.js b/algorithms/binarySearchRecursive.js
new file mode 100644
index 0000000..026430b
--- /dev/null
+++ b/algorithms/binarySearchRecursive.js
@@ -0,0 +1,19 @@
+function binarySearch(arr, val, start = 0, end = arr.length - 1) {
+ const mid = Math.floor((start + end) / 2);
+
+ if (val === arr[mid]) {
+ return mid;
+ }
+
+ if (start>= end) {
+ return -1;
+ }
+
+ return val < arr[mid] + ? binarySearch(arr, val, start, mid - 1) + : binarySearch(arr, val, mid + 1, end); +} + +let arr = [1, 2, 4, 6, 100, 10000]; + +console.log(binarySearch(arr, 2)); From 1caac4b43b84a22d7891a4b1f762ab90a59d26be Mon Sep 17 00:00:00 2001 From: Lakshman
Date: 2020年12月12日 20:06:02 +0600
Subject: [PATCH 05/56] Update README.md
---
README.md | 49 ++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 48 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index bb0c9bf..5f50214 100644
--- a/README.md
+++ b/README.md
@@ -68,4 +68,51 @@
let str = "Hello world, welcome to the JS Universe.";
console.log(str.length); // 40
- ```
\ No newline at end of file
+ ```
+
+
+- [1.6](#length) **Interview Qus**: Tricky JavaScript Interview Questions and Answers
+
+ ```javascript
+// remove duplicates form and array
+let arr = [1, 2, 2, 3, 4];
+
+console.log([...new Set(arr)]);
+
+// output test 1
+console.log(5 < 6 < 7); // true // 5 < 6 => true => true < 7 => true = 1 => 1 < 7 => true
+
+console.log(7> 6> 5); // false // 7> 6 => true => true> 5 => true = 1 => 1> 5 = false
+
+console.log(Math.max()); // -Infinity lowest min number in js
+console.log(Math.max(1, 2, 3, 4)); // 4
+
+
+// obj
+let profile = {
+ name: 'Lakshman'
+};
+
+// Object.freeze(profile); // freeze don't allow insert and update
+Object.seal(profile); // freeze don't allow insert, remove but allow update
+
+profile.name = 'Gope';
+
+console.log(profile);
+
+// obj
+let user = {
+ name: 'Gope'
+};
+
+// age not allow any update but name does
+Object.defineProperty(user, 'age', {
+ value: 4,
+ writable: false
+})
+
+user.name = 'Lakshman'
+user.age = 5;
+
+console.log(user); // TypeError: Cannot assign to read only property 'age' of object '#'
+ ```
From 70a9b666ab602c53a2024440fa7a8db8d8a00f33 Mon Sep 17 00:00:00 2001
From: Lakshman
Date: 2020年12月27日 18:37:01 +0600
Subject: [PATCH 06/56] Create no-loop.js
---
js-coding-technique/no-loop.js | 12 ++++++++++++
1 file changed, 12 insertions(+)
create mode 100644 js-coding-technique/no-loop.js
diff --git a/js-coding-technique/no-loop.js b/js-coding-technique/no-loop.js
new file mode 100644
index 0000000..31bbbf9
--- /dev/null
+++ b/js-coding-technique/no-loop.js
@@ -0,0 +1,12 @@
+// function repeater(x) {
+// if (x> 10) return 0;
+
+// console.log(x++);
+// // x++;
+// return repeater(x);
+// }
+
+// repeater(1);
+
+const helloPrint = num => num < 11 && (console.log(num), helloPrint(++num)); +helloPrint(1); From 7bd0e9765269a1ed832c4f1e97f256db6621246a Mon Sep 17 00:00:00 2001 From: Lakshman
Date: Sun, 3 Jan 2021 23:30:05 +0600
Subject: [PATCH 07/56] Create arrObj.js
---
Interview-Questions/arrObj.js | 117 ++++++++++++++++++++++++++++++++++
1 file changed, 117 insertions(+)
create mode 100644 Interview-Questions/arrObj.js
diff --git a/Interview-Questions/arrObj.js b/Interview-Questions/arrObj.js
new file mode 100644
index 0000000..54d7767
--- /dev/null
+++ b/Interview-Questions/arrObj.js
@@ -0,0 +1,117 @@
+/**
+ * QUESTION 01
+ * OUTPUT
+ */
+
+let obj = {
+ a: 10,
+ b: 20
+};
+
+let obj2 = {
+ a: 10,
+ b: 20
+};
+
+console.log(obj == obj2);
+console.log(obj === obj2);
+
+let obj3 = obj;
+
+console.log(obj3 == obj);
+console.log(obj3 === obj);
+
+/**
+ * QUESTION 02
+ * OUTPUT
+ */
+
+var arr = [1, 2, 3, 4, 5];
+
+for (var i = 0; i < arr.length; i++) { + setTimeout(() => console.log(arr[i]), 500);
+}
+
+const arr1 = [1, 2, 3, 4, 5];
+
+for (let i = 0; i < arr1.length; i++) { + setTimeout(() => console.log(arr1[i]), 500);
+}
+
+/**
+ * QUESTION 03
+ * OUTPUT
+ */
+
+console.log(1);
+setTimeout(() => console.log(2), 0);
+console.log(3);
+Promise.resolve(console.log(4));
+
+/**
+ * QUESTION 04
+ * How to compare two arrays
+ */
+
+let a1 = [1, 2, 3];
+let a2 = [1, 2, 3];
+
+console.log(a1 == a2);
+console.log(JSON.stringify(a1) == JSON.stringify(a2));
+
+/**
+ * QUESTION 05
+ * Calculate total point (using reduce) and avg result
+ */
+
+let EXAM = [
+ {
+ Subeject: "English",
+ result: {
+ point: 80,
+ grade: "A+"
+ }
+ },
+ {
+ Subeject: "Physics",
+ result: {
+ point: 85,
+ grade: "A+"
+ }
+ },
+ {
+ Subeject: "Math",
+ result: {
+ point: 89,
+ grade: "A+"
+ }
+ }
+];
+
+let totalRes = 0;
+EXAM.map(subject => (totalRes += subject.result.point));
+
+console.log(totalRes);
+console.log((totalRes / EXAM.length).toFixed(2));
+
+let res = EXAM.reduce((accumulator, currentValue) => accumulator + currentValue.result.point, 0);
+console.log(res);
+
+/**
+ * QUESTION 06
+ *
+ * Merge two objects in one object
+ */
+
+let obj1 = {
+ a: 10,
+ b: 20
+};
+
+let obj2 = {
+ c: 30,
+ d: 20
+};
+
+obj1 = { ...obj1, ...obj2 };
+console.log(obj1);
From cdcaeb6ad6a5593b8565d64c5e1e46ce4ab6a149 Mon Sep 17 00:00:00 2001
From: Lakshman
Date: 2021年1月11日 10:42:50 +0600
Subject: [PATCH 08/56] Create removeDuplicates.js
---
Array/removeDuplicates.js | 13 +++++++++++++
1 file changed, 13 insertions(+)
create mode 100644 Array/removeDuplicates.js
diff --git a/Array/removeDuplicates.js b/Array/removeDuplicates.js
new file mode 100644
index 0000000..fa22f96
--- /dev/null
+++ b/Array/removeDuplicates.js
@@ -0,0 +1,13 @@
+const fruits = ['🥑', '🍊', '🍇', '🍏', '🍎', '🍑', '🍑'];
+
+// way 1
+console.log('way 1 ', fruits.reduce((uniqueArray, fruit) => {
+ uniqueArray.indexOf(fruit) === -1 && uniqueArray.push(fruit);
+ return uniqueArray;
+}, []))
+
+// way 2
+console.log('way 2 ', fruits.filter((fruit, index) => fruits.indexOf(fruit) === index))
+
+// way 3
+console.log('way 3 ', [...new Set(fruits)])
From 5cb9b01ebe26d89888b704d77b82c72cca3f873a Mon Sep 17 00:00:00 2001
From: Lakshman
Date: 2021年1月12日 00:22:33 +0600
Subject: [PATCH 09/56] Update arrObj.js
---
Interview-Questions/arrObj.js | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/Interview-Questions/arrObj.js b/Interview-Questions/arrObj.js
index 54d7767..b47f5ab 100644
--- a/Interview-Questions/arrObj.js
+++ b/Interview-Questions/arrObj.js
@@ -115,3 +115,32 @@ let obj2 = {
obj1 = { ...obj1, ...obj2 };
console.log(obj1);
+
+
+// more test
+const a = [1, 2, 5, 7, 9];
+const b = [2, 5, 7, 12, 100];
+
+// const c = [...a, ...b];
+
+const c = a.concat(b).sort((a, b) => a> b)
+
+console.log(c)
+
+
+const obj = {
+ x: 1,
+ getX() {
+ const inner = function() {
+ console.log(this.x);
+ }
+
+ inner.bind(this)();
+ }
+}
+
+obj.getX();
+
+const arrayTotal = a.reduce((t, i) => t+i);
+
+console.log(arrayTotal)
From 894aec530cbc01ca91c3cf7c2d2977a0473275be Mon Sep 17 00:00:00 2001
From: Lakshman
Date: 2021年1月14日 16:30:36 +0600
Subject: [PATCH 10/56] Create func.js
---
Interview-Questions/func.js | 11 +++++++++++
1 file changed, 11 insertions(+)
create mode 100644 Interview-Questions/func.js
diff --git a/Interview-Questions/func.js b/Interview-Questions/func.js
new file mode 100644
index 0000000..936c234
--- /dev/null
+++ b/Interview-Questions/func.js
@@ -0,0 +1,11 @@
+// what is output?
+const foo = () => {
+ let a = b = 10;
+ a++;
+ return a
+}
+
+foo();
+
+console.log(a);
+console.log(b);
From b5ab2a8373425f516955ff5fd97e7688ebca6163 Mon Sep 17 00:00:00 2001
From: Lakshman
Date: 2021年1月19日 23:34:25 +0600
Subject: [PATCH 11/56] Update binarySearchRecursive.js
---
algorithms/binarySearchRecursive.js | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/algorithms/binarySearchRecursive.js b/algorithms/binarySearchRecursive.js
index 026430b..349b6d9 100644
--- a/algorithms/binarySearchRecursive.js
+++ b/algorithms/binarySearchRecursive.js
@@ -1,19 +1,17 @@
-function binarySearch(arr, val, start = 0, end = arr.length - 1) {
+const binarySearch = (arr, val, start = 0, end = arr.length - 1) => {
const mid = Math.floor((start + end) / 2);
- if (val === arr[mid]) {
- return mid;
- }
+ if (val === arr[mid]) return mid;
- if (start>= end) {
- return -1;
- }
+ if (start>= end) return -1;
return val < arr[mid] ? binarySearch(arr, val, start, mid - 1) : binarySearch(arr, val, mid + 1, end); -} +}; -let arr = [1, 2, 4, 6, 100, 10000]; +const arr = [1, 9, 5, 7, 2, 4, 8, 6].sort(); -console.log(binarySearch(arr, 2)); +const result = binarySearch(arr, 2); + +console.log(result !== -1 ? `Element is present at index ${result}` : 'Element is not present in array'); From 928480b9e30bdcce1acd45192fd060f784883d30 Mon Sep 17 00:00:00 2001 From: Lakshman
Date: 2021年1月20日 13:28:33 +0600
Subject: [PATCH 12/56] Create bubbleSortRecursive.js
---
algorithms/bubbleSortRecursive.js | 34 +++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
create mode 100644 algorithms/bubbleSortRecursive.js
diff --git a/algorithms/bubbleSortRecursive.js b/algorithms/bubbleSortRecursive.js
new file mode 100644
index 0000000..ef024b6
--- /dev/null
+++ b/algorithms/bubbleSortRecursive.js
@@ -0,0 +1,34 @@
+function bubbleSort(arr, iteration) {
+ if (iteration === 0) return;
+
+ bubbleSwap(arr, 0, 1, iteration);
+ bubbleSort(arr, iteration - 1);
+}
+
+
+function bubbleSwap(arr, i, j, n) {
+
+ if (j>= n) return;
+
+ // swap
+ if (arr[i]> arr[j]) [arr[i], arr[j]] = [arr[j], arr[i]];
+
+
+ bubbleSwap(arr, i + 1, j + 1, n);
+}
+
+
+function sort(arr) {
+ const n = arr.length;
+
+ if (n <= 1) return; + + bubbleSort(arr, n); + +} + +const arr = [1, 8, 6, 5, 4, 9]; + +sort(arr); + +console.log(arr) From 099355e3f93d6ed961007c4b149e6c0fa0acd8ff Mon Sep 17 00:00:00 2001 From: Lakshman
Date: 2021年1月20日 15:18:52 +0600
Subject: [PATCH 13/56] Update bubbleSortRecursive.js
---
algorithms/bubbleSortRecursive.js | 16 +++-------------
1 file changed, 3 insertions(+), 13 deletions(-)
diff --git a/algorithms/bubbleSortRecursive.js b/algorithms/bubbleSortRecursive.js
index ef024b6..47100a9 100644
--- a/algorithms/bubbleSortRecursive.js
+++ b/algorithms/bubbleSortRecursive.js
@@ -7,28 +7,18 @@ function bubbleSort(arr, iteration) {
function bubbleSwap(arr, i, j, n) {
-
if (j>= n) return;
// swap
if (arr[i]> arr[j]) [arr[i], arr[j]] = [arr[j], arr[i]];
-
bubbleSwap(arr, i + 1, j + 1, n);
}
-
-function sort(arr) {
- const n = arr.length;
-
- if (n <= 1) return; - - bubbleSort(arr, n); - -} - const arr = [1, 8, 6, 5, 4, 9]; -sort(arr); +if (arr.length>= 1) bubbleSort(arr, arr.length)
console.log(arr)
+
+// tc => O(n^2)
From fe96b7a38d2919851bf249c9bf9ee6ff483b802b Mon Sep 17 00:00:00 2001
From: Lakshman
Date: 2021年1月22日 16:03:51 +0600
Subject: [PATCH 14/56] Update arrObj.js
---
Interview-Questions/arrObj.js | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/Interview-Questions/arrObj.js b/Interview-Questions/arrObj.js
index b47f5ab..4ecf07e 100644
--- a/Interview-Questions/arrObj.js
+++ b/Interview-Questions/arrObj.js
@@ -144,3 +144,11 @@ obj.getX();
const arrayTotal = a.reduce((t, i) => t+i);
console.log(arrayTotal)
+
+
+// OUTPUT
+const arr = [1, 2, 3, 4, 5];
+
+arr.push(arr.push(arr.push(arr.pop())))
+
+console.log(arr);
From f3e68adb2f682d4fbfff510494455a13686c44f5 Mon Sep 17 00:00:00 2001
From: Lakshman
Date: 2021年2月15日 12:01:32 +0600
Subject: [PATCH 15/56] Create searchAnyValue.js
---
05 - Objects-And-Functions/searchAnyValue.js | 22 ++++++++++++++++++++
1 file changed, 22 insertions(+)
create mode 100644 05 - Objects-And-Functions/searchAnyValue.js
diff --git a/05 - Objects-And-Functions/searchAnyValue.js b/05 - Objects-And-Functions/searchAnyValue.js
new file mode 100644
index 0000000..043eb4f
--- /dev/null
+++ b/05 - Objects-And-Functions/searchAnyValue.js
@@ -0,0 +1,22 @@
+const arr = [{
+ name: 'xyz',
+ grade: 'xs'
+}, {
+ name: 'yaya',
+ grade: 'xa'
+}, {
+ name: 'xf',
+ frade: 'dd'
+}, {
+ name: 'a',
+ grade: 'b'
+}];
+
+
+function filterIt(arr, searchKey) {
+ return arr.filter(obj => Object.keys(obj).some(key => obj[key].includes(searchKey)));
+}
+
+console.log("find 'x'", filterIt(arr,"x"));
+console.log("find 'a'", filterIt(arr,"a"));
+console.log("find 'z'", filterIt(arr,"z"));
From 8f6a336da409778c47161944aa85e5c3f8af0d7b Mon Sep 17 00:00:00 2001
From: Lakshman
Date: 2021年2月23日 10:35:58 +0600
Subject: [PATCH 16/56] Update arrObj.js
---
Interview-Questions/arrObj.js | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/Interview-Questions/arrObj.js b/Interview-Questions/arrObj.js
index 4ecf07e..5b0a7d8 100644
--- a/Interview-Questions/arrObj.js
+++ b/Interview-Questions/arrObj.js
@@ -152,3 +152,10 @@ const arr = [1, 2, 3, 4, 5];
arr.push(arr.push(arr.push(arr.pop())))
console.log(arr);
+
+
+// OUTPUT
+const arrayOfOddNumbers = [1, 3, 5];
+arrayOfOddNumbers[100] = 199;
+console.log(arrayOfOddNumbers.length);
+
From 708e2a298f201254c53ed6cab91b77b4c8463788 Mon Sep 17 00:00:00 2001
From: Lakshman
Date: Wed, 3 Mar 2021 10:38:48 +0600
Subject: [PATCH 17/56] Create arrayFalsyBouncer.js
---
js-coding-technique/arrayFalsyBouncer.js | 9 +++++++++
1 file changed, 9 insertions(+)
create mode 100644 js-coding-technique/arrayFalsyBouncer.js
diff --git a/js-coding-technique/arrayFalsyBouncer.js b/js-coding-technique/arrayFalsyBouncer.js
new file mode 100644
index 0000000..7312ffa
--- /dev/null
+++ b/js-coding-technique/arrayFalsyBouncer.js
@@ -0,0 +1,9 @@
+const evenNumberSquared = [1,2,3,4].map(n => {
+ if (n % 2 !== 0) {
+ return null;
+ }
+
+ return n * n;
+}).filter(Boolean);
+
+console.log(evenNumberSquared)
From be2860682ba812f0597c5864cfc911c98aebe80d Mon Sep 17 00:00:00 2001
From: Lakshman
Date: 2021年3月15日 16:13:42 +0600
Subject: [PATCH 18/56] Create toFixed.js
---
BuildIn-Methods/toFixed.js | 10 ++++++++++
1 file changed, 10 insertions(+)
create mode 100644 BuildIn-Methods/toFixed.js
diff --git a/BuildIn-Methods/toFixed.js b/BuildIn-Methods/toFixed.js
new file mode 100644
index 0000000..e42fd92
--- /dev/null
+++ b/BuildIn-Methods/toFixed.js
@@ -0,0 +1,10 @@
+const fixNum = (num, n = 2) => Number.parseFloat(num).toFixed(n);
+
+console.log(fixNum(123.456));
+// expected output: "123.46"
+
+console.log(fixNum(0.004));
+// expected output: "0.00"
+
+console.log(fixNum('1.23e+5', 4));
+// expected output: "123000.0000"
From 087105501a2ae58d55e155cfdedfe597982d6661 Mon Sep 17 00:00:00 2001
From: Lakshman
Date: 2021年3月18日 16:21:40 +0600
Subject: [PATCH 19/56] Create validURL.js
---
Regex/validURL.js | 11 +++++++++++
1 file changed, 11 insertions(+)
create mode 100644 Regex/validURL.js
diff --git a/Regex/validURL.js b/Regex/validURL.js
new file mode 100644
index 0000000..b923707
--- /dev/null
+++ b/Regex/validURL.js
@@ -0,0 +1,11 @@
+const validURL = (str) => {
+ const pattern = new RegExp('^(https?:\\/\\/)?'+ // protocol
+ '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // domain name
+ '((\\d{1,3}\\.){3}\\d{1,3}))'+ // OR ip (v4) address
+ '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // port and path
+ '(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string
+ '(\\#[-a-z\\d_]*)?$','i'); // fragment locator
+ return !!pattern.test(str);
+}
+
+console.log(validURL("https://www.google.com/"));
From 88b4884d5c017dce47e665c2d1e52d154ea4e86a Mon Sep 17 00:00:00 2001
From: Lakshman
Date: 2021年4月24日 22:08:22 +0600
Subject: [PATCH 20/56] Update func.js
---
Interview-Questions/func.js | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/Interview-Questions/func.js b/Interview-Questions/func.js
index 936c234..e9d4bcb 100644
--- a/Interview-Questions/func.js
+++ b/Interview-Questions/func.js
@@ -9,3 +9,28 @@ foo();
console.log(a);
console.log(b);
+
+
+// output
+function createIncrement() {
+ let count = 0;
+
+ function increment() {
+ count++;
+ }
+
+ let message = `Count is ${count}`;
+ function log() {
+ console.log(message);
+ }
+
+ return [increment, log];
+}
+
+const [increment, log] = createIncrement();
+
+increment();
+increment();
+increment();
+
+log();
From 4fc48fc989242204411a579728384e6939a387b4 Mon Sep 17 00:00:00 2001
From: Lakshman
Date: 2021年5月13日 22:16:04 +0600
Subject: [PATCH 21/56] Update byeTryCatchErrorHandling.js
---
.../byeTryCatchErrorHandling.js | 20 +++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/Asynchronous-JavaScript/byeTryCatchErrorHandling.js b/Asynchronous-JavaScript/byeTryCatchErrorHandling.js
index 7a37ab2..e8360f5 100644
--- a/Asynchronous-JavaScript/byeTryCatchErrorHandling.js
+++ b/Asynchronous-JavaScript/byeTryCatchErrorHandling.js
@@ -44,3 +44,23 @@ exports.createOne = Model =>
},
});
});
+
+// another
+
+const awaitHandlerFactory = (middleware) => {
+ return async (req, res, next) => {
+ try {
+ await middleware(req, res, next);
+ } catch (err) {
+ next(err);
+ }
+ };
+};
+// and use it this way:
+app.get(
+ "/",
+ awaitHandlerFactory(async (request, response) => {
+ const result = await getContent();
+ response.send(result);
+ })
+);
From ec4f9d963a5f56d45fc32de11b476819852d7616 Mon Sep 17 00:00:00 2001
From: Lakshman
Date: Wed, 4 Aug 2021 16:02:50 +0600
Subject: [PATCH 22/56] Create renameDuplicates.js
---
js-coding-technique/renameDuplicates.js | 47 +++++++++++++++++++++++++
1 file changed, 47 insertions(+)
create mode 100644 js-coding-technique/renameDuplicates.js
diff --git a/js-coding-technique/renameDuplicates.js b/js-coding-technique/renameDuplicates.js
new file mode 100644
index 0000000..7981800
--- /dev/null
+++ b/js-coding-technique/renameDuplicates.js
@@ -0,0 +1,47 @@
+// 1
+var array = [
+{
+ name: "Steven Smith",
+ Country: "England",
+ Age: 35
+},
+{
+ name: "Hannah Reed",
+ Country: "Scottland",
+ Age: 23
+},
+{
+ name: "Steven Smith",
+ Country: "Spain",
+ Age: 35
+},
+];
+
+ let names = {};
+ arr.forEach(obj => {
+ if (names[obj.name]) {
+ obj.name += "_" + ++names[obj.name];
+ } else {
+ names[obj.name] = 1;
+ }
+ });
+
+
+// 2
+ function renameFiles(arr) {
+ let count = {};
+ arr.forEach((x, i) => {
+ if (arr.indexOf(x) !== i) {
+ let c = x in count ? (count[x] = count[x] + 1) : (count[x] = 1);
+ let j = c + 1;
+ let k = `${x }(${ j })`;
+
+ while (arr.indexOf(k) !== -1) k = `${x }(${ ++j })`;
+ arr[i] = k;
+ }
+ });
+ return arr;
+ }
+
+ let res = renameFiles(['a(1)', 'a(6)', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a']);
+ console.log(res);
From 5384212719abc81dd56f9a21a8f628148907024d Mon Sep 17 00:00:00 2001
From: Lakshman
Date: Fri, 6 Aug 2021 16:29:35 +0600
Subject: [PATCH 23/56] Update renameDuplicates.js
---
js-coding-technique/renameDuplicates.js | 131 ++++++++++++++++++++++++
1 file changed, 131 insertions(+)
diff --git a/js-coding-technique/renameDuplicates.js b/js-coding-technique/renameDuplicates.js
index 7981800..f035b78 100644
--- a/js-coding-technique/renameDuplicates.js
+++ b/js-coding-technique/renameDuplicates.js
@@ -45,3 +45,134 @@ var array = [
let res = renameFiles(['a(1)', 'a(6)', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a']);
console.log(res);
+
+
+// Other should update
+function renameFiles(arrObj, renameField='contents') {
+ let arr = [];
+ if (renameField === 'contents') {
+ arrObj.forEach((child) => {
+ arr.push(child.properties[renameField]);
+ });
+ } else {
+ arrObj.forEach((child) => {
+ arr.push(child.properties.attributes[renameField]);
+ });
+ }
+
+ let count = {};
+ arr.forEach((x, i) => {
+ if (arr.indexOf(x) !== i) {
+ let c = x in count ? (count[x] = count[x] + 1) : (count[x] = 1);
+ let j = c + 1;
+ let k = `${x} (${j})`;
+
+ while (arr.indexOf(k) !== -1) k = `${x} (${++j})`;
+ arr[i] = k;
+ }
+ });
+
+ for (let i = 0; i < arrObj.length; i++) { + arrObj[i].properties.contents = arr[i]; + } + + return arrObj; +} + +// let res = renameFiles(['a(1)', 'a(6)', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a']); +let res = renameFiles([ + { + id: 1, + properties: { contents: 'a' }, + }, + { + id: 2, + properties: { contents: 'a' }, + }, + { + id: 3, + properties: { contents: 'a' }, + }, + { + id: 1, + properties: { contents: 'a' }, + }, + { + id: 1, + properties: { contents: 'a (3)' }, + }, +]); +console.log(res); + +// function renameDuplicates(arr) { +// let count = {}; +// arr.forEach((x, i) => {
+// if (arr.indexOf(x) !== i) {
+// console.log(arr.indexOf(x), i);
+// let c = x in count ? (count[x] = count[x] + 1) : (count[x] = 1);
+// let j = c + 1;
+// let k = `${x}(${j})`;
+
+// while (arr.indexOf(k) !== -1) k = `${x}(${++j})`;
+// arr[i] = k;
+// }
+// });
+// return arr;
+// }
+
+// let res1 = renameDuplicates(['a(1)', 'a(6)', 'a(1)', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a']);
+// console.log(res1);
+
+const renameDuplicates = (childrens) => {
+ // console.log({ inputChildrens: childrens });
+ let temp = childrens.length;
+
+ childrens = JSON.parse(JSON.stringify(childrens));
+ let count = {};
+ childrens.forEach((child) => {
+ if (count[child.properties.contents]) {
+ child.properties.contents += ` (${++count[child.properties.contents]})`;
+ while (temp) {
+ temp--;
+ if (childrens[temp].properties.contents === child.properties.contents || count[child.properties.contents])
+ child.properties.contents += ` (${1})`;
+ }
+ } else {
+ count[child.properties.contents] = 1;
+ }
+
+ // if (count[child.properties.attributes.value]) {
+ // child.properties.attributes.value += ` (${++count[child.properties.attributes.value]})`;
+ // } else {
+ // count[child.properties.attributes.value] = 1;
+ // }
+ });
+
+ return childrens;
+};
+
+const res1 = renameDuplicates([
+ {
+ id: 1,
+ properties: { contents: 'a' },
+ },
+ {
+ id: 2,
+ properties: { contents: 'a' },
+ },
+ {
+ id: 3,
+ properties: { contents: 'a' },
+ },
+ {
+ id: 1,
+ properties: { contents: 'a (2)' },
+ },
+ {
+ id: 1,
+ properties: { contents: 'a (3)' },
+ },
+]);
+
+// console.log(res1);
+
From bb878d22bc7c8660d6bb634aafa205f5392286b7 Mon Sep 17 00:00:00 2001
From: Lakshman
Date: Wed, 1 Sep 2021 11:40:57 +0600
Subject: [PATCH 24/56] Create removeEmptyKeys.js
---
js-coding-technique/removeEmptyKeys.js | 5 +++++
1 file changed, 5 insertions(+)
create mode 100644 js-coding-technique/removeEmptyKeys.js
diff --git a/js-coding-technique/removeEmptyKeys.js b/js-coding-technique/removeEmptyKeys.js
new file mode 100644
index 0000000..87f5037
--- /dev/null
+++ b/js-coding-technique/removeEmptyKeys.js
@@ -0,0 +1,5 @@
+export const removeEmptyKeys = (obj) =>
+ Object.entries(obj).reduce(
+ (accumulator, [key, value]) => (value ? ((accumulator[key] = value), accumulator) : accumulator),
+ {},
+ );
From d758c4151a26d876f490581531e068a1da8a8569 Mon Sep 17 00:00:00 2001
From: Lakshman
Date: Fri, 8 Oct 2021 11:25:12 +0600
Subject: [PATCH 25/56] Create getTextTotalLine.js
---
js-coding-technique/getTextTotalLine.js | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
create mode 100644 js-coding-technique/getTextTotalLine.js
diff --git a/js-coding-technique/getTextTotalLine.js b/js-coding-technique/getTextTotalLine.js
new file mode 100644
index 0000000..cb63790
--- /dev/null
+++ b/js-coding-technique/getTextTotalLine.js
@@ -0,0 +1,24 @@
+const getTextTotalLine = (el) => {
+ let divHeight = 1;
+ if (el.tagName === 'TEXTAREA') {
+ divHeight = el.scrollHeight;
+ } else {
+ divHeight = el.offsetHeight;
+ }
+ let lineHeight = window
+ .getComputedStyle(el, null)
+ .getPropertyValue('line-height');
+ lineHeight = parseFloat(lineHeight.split('px')[0]);
+ let totalLine = Math.ceil(divHeight / lineHeight);
+ return totalLine;
+ }
+
+const onChange = () => {
+ const totalLine = getTextTotalLine(anchorEl.current);
+}
+
+return (
+
+
+
+ );
From 689abfc8b9b30f01eb91cb879d2e426b21bf6248 Mon Sep 17 00:00:00 2001
From: Lakshman
Date: Sat, 9 Oct 2021 23:09:50 +0600
Subject: [PATCH 26/56] Delete getTextTotalLine.js
---
js-coding-technique/getTextTotalLine.js | 24 ------------------------
1 file changed, 24 deletions(-)
delete mode 100644 js-coding-technique/getTextTotalLine.js
diff --git a/js-coding-technique/getTextTotalLine.js b/js-coding-technique/getTextTotalLine.js
deleted file mode 100644
index cb63790..0000000
--- a/js-coding-technique/getTextTotalLine.js
+++ /dev/null
@@ -1,24 +0,0 @@
-const getTextTotalLine = (el) => {
- let divHeight = 1;
- if (el.tagName === 'TEXTAREA') {
- divHeight = el.scrollHeight;
- } else {
- divHeight = el.offsetHeight;
- }
- let lineHeight = window
- .getComputedStyle(el, null)
- .getPropertyValue('line-height');
- lineHeight = parseFloat(lineHeight.split('px')[0]);
- let totalLine = Math.ceil(divHeight / lineHeight);
- return totalLine;
- }
-
-const onChange = () => {
- const totalLine = getTextTotalLine(anchorEl.current);
-}
-
-return (
-
-
-
- );
From cc92a491d2ebbe36d82c51089616508e0868cea2 Mon Sep 17 00:00:00 2001
From: Lakshman
Date: 2021年10月21日 19:36:14 +0600
Subject: [PATCH 27/56] Update README.md
---
README.md | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 5f50214..888e422 100644
--- a/README.md
+++ b/README.md
@@ -69,7 +69,7 @@
let str = "Hello world, welcome to the JS Universe.";
console.log(str.length); // 40
```
-
+
- [1.6](#length) **Interview Qus**: Tricky JavaScript Interview Questions and Answers
@@ -116,3 +116,10 @@ user.age = 5;
console.log(user); // TypeError: Cannot assign to read only property 'age' of object '#'
```
+
+
+- [1.5](#rename) **rename**: Rename multiple files extentions at once by a command (Just for Win).
+
+ ```javascript
+ Get-ChildItem *.css | Rename-Item -NewName { $_.name -Replace '\.css','.scss' }
+ ```
From c726aaf969ae8e4c4a9846b7544b50bbf8084642 Mon Sep 17 00:00:00 2001
From: Lakshman
Date: 2021年10月24日 12:52:32 +0600
Subject: [PATCH 28/56] Update func.js
---
Interview-Questions/func.js | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/Interview-Questions/func.js b/Interview-Questions/func.js
index e9d4bcb..e7ade2a 100644
--- a/Interview-Questions/func.js
+++ b/Interview-Questions/func.js
@@ -34,3 +34,24 @@ increment();
increment();
log();
+
+// Console sequence output?
+function run () {
+ const promise = new Promise((resolve) => {
+ resolve('promise');
+ })
+
+ setTimeout(() => {
+ console.log('setTimeout');
+ });
+
+ promise.then(res => console.log(res))
+
+ console.log('log');
+}
+
+run();
+
+// How does the Javascript interprets the following code?
+console.log(x);
+var x = 100;
From 5d498a85a58889dc91569a669bf17ae421de2d22 Mon Sep 17 00:00:00 2001
From: Lakshman
Date: 2021年10月24日 12:56:33 +0600
Subject: [PATCH 29/56] Update arrObj.js
---
Interview-Questions/arrObj.js | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/Interview-Questions/arrObj.js b/Interview-Questions/arrObj.js
index 5b0a7d8..a4028df 100644
--- a/Interview-Questions/arrObj.js
+++ b/Interview-Questions/arrObj.js
@@ -159,3 +159,13 @@ const arrayOfOddNumbers = [1, 3, 5];
arrayOfOddNumbers[100] = 199;
console.log(arrayOfOddNumbers.length);
+
+
+// OUTPUT
+class MyClass extends (String, Array) {
+ construct() {}
+}
+
+const a = new MyClass()
+
+console.log(a instanceof Array); // true
From 165008943d0bf7d98e19ab9355a5197ece7d69d0 Mon Sep 17 00:00:00 2001
From: Lakshman
Date: 2021年11月17日 12:00:18 +0600
Subject: [PATCH 30/56] Create getYoutubeVideoId.js
---
js-coding-technique/getYoutubeVideoId.js | 7 +++++++
1 file changed, 7 insertions(+)
create mode 100644 js-coding-technique/getYoutubeVideoId.js
diff --git a/js-coding-technique/getYoutubeVideoId.js b/js-coding-technique/getYoutubeVideoId.js
new file mode 100644
index 0000000..c85d4a3
--- /dev/null
+++ b/js-coding-technique/getYoutubeVideoId.js
@@ -0,0 +1,7 @@
+const getYoutubeEmbedUrl = (url) => {
+ const youtubeVideoId = url.match(
+ /^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/)|(?:(?:watch)?\?v(?:i)?=|\&v(?:i)?=))([^#\&\?]*).*/,
+ );
+
+ return `https://www.youtube.com/embed/${youtubeVideoId[1]}`;
+};
From c094155fbf6839f76f412dd1323ed16ac0c4138c Mon Sep 17 00:00:00 2001
From: Lakshman
Date: 2021年11月24日 12:09:45 +0600
Subject: [PATCH 31/56] Create insertAt.js
---
js-coding-technique/insertAt.js | 15 +++++++++++++++
1 file changed, 15 insertions(+)
create mode 100644 js-coding-technique/insertAt.js
diff --git a/js-coding-technique/insertAt.js b/js-coding-technique/insertAt.js
new file mode 100644
index 0000000..4e79af1
--- /dev/null
+++ b/js-coding-technique/insertAt.js
@@ -0,0 +1,15 @@
+// Insert an item into an array at a specific index (Immutable insertion)
+/**
+ *
+ * @param {Array} arr
+ * @param {Int} index
+ * @param {*} values
+ * @returns arr {New Array}
+ *
+ * @demo let bar = insertAt(arr, 2, 'a', 'b')
+ */
+export const insertAt = (arr, index) => {
+ const items = Array.prototype.slice.call(arguments, 2);
+
+ return [].concat(arr.slice(0, index), items, arr.slice(index));
+};
From a12b69aa82f4f3a6e3a6ec1a570e5d7562c99911 Mon Sep 17 00:00:00 2001
From: Lakshman
Date: 2021年11月24日 12:10:35 +0600
Subject: [PATCH 32/56] Create searchObjInArray.js
---
js-coding-technique/searchObjInArray.js | 15 +++++++++++++++
1 file changed, 15 insertions(+)
create mode 100644 js-coding-technique/searchObjInArray.js
diff --git a/js-coding-technique/searchObjInArray.js b/js-coding-technique/searchObjInArray.js
new file mode 100644
index 0000000..460189b
--- /dev/null
+++ b/js-coding-technique/searchObjInArray.js
@@ -0,0 +1,15 @@
+// Find a value in an array of objects in Javascript
+/**
+ *
+ * @param {String} value
+ * @param {String} key
+ * @param {Array} arr
+ * @returns item {Object}
+ */
+export const searchObjInArray = (value, key, arr) => {
+ for (let i = 0; i < arr.length; i++) { + if (arr[i][key] === value) { + return arr[i]; + } + } +}; From 08bd9427c0179d956c22ae73eec44c7309a34582 Mon Sep 17 00:00:00 2001 From: Lakshman
Date: 2021年11月24日 12:49:13 +0600
Subject: [PATCH 33/56] Update insertAt.js
---
js-coding-technique/insertAt.js | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)
diff --git a/js-coding-technique/insertAt.js b/js-coding-technique/insertAt.js
index 4e79af1..df95ea3 100644
--- a/js-coding-technique/insertAt.js
+++ b/js-coding-technique/insertAt.js
@@ -1,15 +1,11 @@
// Insert an item into an array at a specific index (Immutable insertion)
/**
- *
- * @param {Array} arr
- * @param {Int} index
- * @param {*} values
+ *
+ * @param {Array} array
+ * @param {Int} index
+ * @param {*} items
* @returns arr {New Array}
- *
- * @demo let bar = insertAt(arr, 2, 'a', 'b')
+ *
+ * @demo let bar = insertAt(array, 2, 'a', 'b')
*/
-export const insertAt = (arr, index) => {
- const items = Array.prototype.slice.call(arguments, 2);
-
- return [].concat(arr.slice(0, index), items, arr.slice(index));
-};
+export const insertAt = (array, index, ...items) => [...array.slice(0, index), ...items, ...array.slice(index)];
From 910e2cb3cf1dbed8b3820e8e6585653efed2dc1c Mon Sep 17 00:00:00 2001
From: Lakshman
Date: 2021年11月29日 13:48:32 +0600
Subject: [PATCH 34/56] Create renameObjectKey.js
---
js-coding-technique/renameObjectKey.js | 14 ++++++++++++++
1 file changed, 14 insertions(+)
create mode 100644 js-coding-technique/renameObjectKey.js
diff --git a/js-coding-technique/renameObjectKey.js b/js-coding-technique/renameObjectKey.js
new file mode 100644
index 0000000..7192112
--- /dev/null
+++ b/js-coding-technique/renameObjectKey.js
@@ -0,0 +1,14 @@
+const renameObjectKey = ({ oldObj, oldName, newName }) => {
+ const newObj = {};
+ Object.keys(oldObj).forEach((key) => {
+ const value = oldObj[key];
+
+ if (key === oldName) {
+ newObj[newName] = value;
+ } else {
+ newObj[key] = value;
+ }
+ });
+
+ return newObj;
+};
From df37529e2dba4c0fe3a4345bf29b9b4b75a0085f Mon Sep 17 00:00:00 2001
From: Lakshman
Date: Fri, 7 Jan 2022 17:35:29 +0600
Subject: [PATCH 35/56] Update arrObj.js
---
Interview-Questions/arrObj.js | 3 +++
1 file changed, 3 insertions(+)
diff --git a/Interview-Questions/arrObj.js b/Interview-Questions/arrObj.js
index a4028df..4327ce8 100644
--- a/Interview-Questions/arrObj.js
+++ b/Interview-Questions/arrObj.js
@@ -169,3 +169,6 @@ class MyClass extends (String, Array) {
const a = new MyClass()
console.log(a instanceof Array); // true
+
+// OUTPUT
+["1101100000111110","1101110100011111"].map(s => String.fromCharCode(parseInt(s, 2))).reduce((acc, n) => acc + n, "");
From 1cbbac91b6b04cc5e1d50a3eee273dae73683999 Mon Sep 17 00:00:00 2001
From: Lakshman
Date: Wed, 2 Mar 2022 12:49:45 +0600
Subject: [PATCH 36/56] Create userOS.js
---
js-coding-technique/userOS.js | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
create mode 100644 js-coding-technique/userOS.js
diff --git a/js-coding-technique/userOS.js b/js-coding-technique/userOS.js
new file mode 100644
index 0000000..13fa7c0
--- /dev/null
+++ b/js-coding-technique/userOS.js
@@ -0,0 +1,22 @@
+function getUserOS() {
+ let device = 'Unknown';
+ const ua = {
+ 'Generic Linux': /Linux/i,
+ Android: /Android/i,
+ BlackBerry: /BlackBerry/i,
+ Bluebird: /EF500/i,
+ 'Chrome OS': /CrOS/i,
+ Datalogic: /DL-AXIS/i,
+ Honeywell: /CT50/i,
+ iPad: /iPad/i,
+ iPhone: /iPhone/i,
+ iPod: /iPod/i,
+ macOS: /Macintosh/i,
+ Windows: /IEMobile|Windows/i,
+ Zebra: /TC70|TC55/i,
+ };
+ Object.keys(ua).map((v) => navigator.userAgent.match(ua[v]) && (device = v));
+ return device;
+}
+
+console.log({OS: getUserOS()});
From b58c7ac029de9f8c9d6ac5fe047d0392ce817efb Mon Sep 17 00:00:00 2001
From: Lakshman
Date: Mon, 8 Aug 2022 16:15:42 +0600
Subject: [PATCH 37/56] Update recursiveFunction.js
---
05 - Objects-And-Functions/recursiveFunction.js | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/05 - Objects-And-Functions/recursiveFunction.js b/05 - Objects-And-Functions/recursiveFunction.js
index 46c3f30..15a6a46 100644
--- a/05 - Objects-And-Functions/recursiveFunction.js
+++ b/05 - Objects-And-Functions/recursiveFunction.js
@@ -43,3 +43,14 @@ var factorial = function (number) {
};
console.log(`Factorial = ${factorial(9)}`);
+
+
+// Function
+function countDown(number) {
+ if (number !== 0) countDown.count += number + countDown(number - 1);
+ return countDown.count;
+}
+
+countDown.count = 0;
+console.log(countDown(4));
+
From 2a9c5ced6cb11f9a063eaf96fd7421be9a78a7ad Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Tue, 6 Dec 2022 15:03:42 +0000
Subject: [PATCH 38/56] Bump qs in
/Asynchronous-JavaScript/Asynchronous-Example
Bumps [qs](https://github.com/ljharb/qs) from 6.9.0 to 6.11.0.
- [Release notes](https://github.com/ljharb/qs/releases)
- [Changelog](https://github.com/ljharb/qs/blob/main/CHANGELOG.md)
- [Commits](https://github.com/ljharb/qs/compare/v6.9.0...v6.11.0)
---
updated-dependencies:
- dependency-name: qs
dependency-type: indirect
...
Signed-off-by: dependabot[bot]
---
.../Asynchronous-Example/package-lock.json | 61 ++++++++++++++++++-
1 file changed, 58 insertions(+), 3 deletions(-)
diff --git a/Asynchronous-JavaScript/Asynchronous-Example/package-lock.json b/Asynchronous-JavaScript/Asynchronous-Example/package-lock.json
index 460ab26..21d3c2a 100644
--- a/Asynchronous-JavaScript/Asynchronous-Example/package-lock.json
+++ b/Asynchronous-JavaScript/Asynchronous-Example/package-lock.json
@@ -9,6 +9,15 @@
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
},
+ "call-bind": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz",
+ "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==",
+ "requires": {
+ "function-bind": "^1.1.1",
+ "get-intrinsic": "^1.0.2"
+ }
+ },
"combined-stream": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
@@ -60,6 +69,34 @@
"resolved": "https://registry.npmjs.org/formidable/-/formidable-1.2.1.tgz",
"integrity": "sha512-Fs9VRguL0gqGHkXS5GQiMCr1VhZBxz0JnJs4JmMp/2jL18Fmbzvv7vOFRU+U8TBkHEE/CX1qDXzJplVULgsLeg=="
},
+ "function-bind": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
+ "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A=="
+ },
+ "get-intrinsic": {
+ "version": "1.1.3",
+ "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.3.tgz",
+ "integrity": "sha512-QJVz1Tj7MS099PevUG5jvnt9tSkXN8K14dxQlikJuPt4uD9hHAHjLyLBiLR5zELelBdD9QNRAXZzsJx0WaDL9A==",
+ "requires": {
+ "function-bind": "^1.1.1",
+ "has": "^1.0.3",
+ "has-symbols": "^1.0.3"
+ }
+ },
+ "has": {
+ "version": "1.0.3",
+ "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz",
+ "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==",
+ "requires": {
+ "function-bind": "^1.1.1"
+ }
+ },
+ "has-symbols": {
+ "version": "1.0.3",
+ "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz",
+ "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A=="
+ },
"inherits": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
@@ -93,10 +130,18 @@
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
},
+ "object-inspect": {
+ "version": "1.12.2",
+ "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.2.tgz",
+ "integrity": "sha512-z+cPxW0QGUp0mcqcsgQyLVRDoXFQbXOwBaqyF7VIgI4TWNQsDHrBpUQslRmIfAoYWdYzs6UlKJtB2XJpTaNSpQ=="
+ },
"qs": {
- "version": "6.9.0",
- "resolved": "https://registry.npmjs.org/qs/-/qs-6.9.0.tgz",
- "integrity": "sha512-27RP4UotQORTpmNQDX8BHPukOnBP3p1uUJY5UnDhaJB+rMt9iMsok724XL+UHU23bEFOHRMQ2ZhI99qOWUMGFA=="
+ "version": "6.11.0",
+ "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz",
+ "integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==",
+ "requires": {
+ "side-channel": "^1.0.4"
+ }
},
"readable-stream": {
"version": "3.4.0",
@@ -118,6 +163,16 @@
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
"integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw=="
},
+ "side-channel": {
+ "version": "1.0.4",
+ "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz",
+ "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==",
+ "requires": {
+ "call-bind": "^1.0.0",
+ "get-intrinsic": "^1.0.2",
+ "object-inspect": "^1.9.0"
+ }
+ },
"string_decoder": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz",
From 05a0092c93c95603a083a7453b7eb64feb199bcb Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: 2023年1月24日 01:03:01 +0000
Subject: [PATCH 39/56] Bump cookiejar in
/Asynchronous-JavaScript/Asynchronous-Example
Bumps [cookiejar](https://github.com/bmeck/node-cookiejar) from 2.1.2 to 2.1.4.
- [Release notes](https://github.com/bmeck/node-cookiejar/releases)
- [Commits](https://github.com/bmeck/node-cookiejar/commits)
---
updated-dependencies:
- dependency-name: cookiejar
dependency-type: indirect
...
Signed-off-by: dependabot[bot]
---
.../Asynchronous-Example/package-lock.json | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/Asynchronous-JavaScript/Asynchronous-Example/package-lock.json b/Asynchronous-JavaScript/Asynchronous-Example/package-lock.json
index 460ab26..9d95da4 100644
--- a/Asynchronous-JavaScript/Asynchronous-Example/package-lock.json
+++ b/Asynchronous-JavaScript/Asynchronous-Example/package-lock.json
@@ -23,9 +23,9 @@
"integrity": "sha512-Rd3se6QB+sO1TwqZjscQrurpEPIfO0/yYnSin6Q/rD3mOutHvUrCAhJub3r90uNb+SESBuE0QYoB90YdfatsRg=="
},
"cookiejar": {
- "version": "2.1.2",
- "resolved": "https://registry.npmjs.org/cookiejar/-/cookiejar-2.1.2.tgz",
- "integrity": "sha512-Mw+adcfzPxcPeI+0WlvRrr/3lGVO0bD75SxX6811cxSh1Wbxx7xZBGK1eVtDf6si8rg2lhnUjsVLMFMfbRIuwA=="
+ "version": "2.1.4",
+ "resolved": "https://registry.npmjs.org/cookiejar/-/cookiejar-2.1.4.tgz",
+ "integrity": "sha512-LDx6oHrK+PhzLKJU9j5S7/Y3jM/mUHvD/DeI1WQmJn652iPC5Y4TBzC9l+5OMOXlyTTA+SmVUPm0HQUwpD5Jqw=="
},
"debug": {
"version": "4.1.1",
From c18df604b49321c51483f8570ce663ab3a5f6cf6 Mon Sep 17 00:00:00 2001
From: Lakshman
Date: 2023年2月25日 11:17:57 +0600
Subject: [PATCH 40/56] Find non negative duplicates and how many times
---
Interview-Questions/findDuplicates.js | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
create mode 100644 Interview-Questions/findDuplicates.js
diff --git a/Interview-Questions/findDuplicates.js b/Interview-Questions/findDuplicates.js
new file mode 100644
index 0000000..efd659d
--- /dev/null
+++ b/Interview-Questions/findDuplicates.js
@@ -0,0 +1,22 @@
+// Find non negative duplicates and how many times
+
+let array = [1, 4, -1, 8, 2, 4, 4, 4, 1, -1, 6, 2, 1, 9, 7];
+function findDuplicates(arr) {
+ let duplicateElements = {};
+ arr.forEach((currentValue, currentIndex) => {
+
+ // return currentValue> 0 && arr.indexOf(currentValue) !== currentIndex; // return non negative and duplicate elements
+
+ // find how many times
+ if(currentValue> 0 && arr.indexOf(currentValue) !== currentIndex){
+ duplicateElements[currentValue] = (duplicateElements[currentValue] || 1) + 1;
+ }
+
+ // console.log(currentValue, currentIndex, arr.indexOf(currentValue))
+ });
+
+
+ return duplicateElements;
+}
+
+console.log(findDuplicates(array), Object.keys(findDuplicates(array)));
From 3b53b772d25a10f9a952474a53d27cbaff811524 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: 2023年6月25日 10:35:13 +0000
Subject: [PATCH 41/56] Bump semver and superagent
Bumps [semver](https://github.com/npm/node-semver) to 7.5.3 and updates ancestor dependency [superagent](https://github.com/ladjs/superagent). These dependencies need to be updated together.
Updates `semver` from 6.3.0 to 7.5.3
- [Release notes](https://github.com/npm/node-semver/releases)
- [Changelog](https://github.com/npm/node-semver/blob/main/CHANGELOG.md)
- [Commits](https://github.com/npm/node-semver/compare/v6.3.0...v7.5.3)
Updates `superagent` from 5.1.0 to 5.3.1
- [Release notes](https://github.com/ladjs/superagent/releases)
- [Changelog](https://github.com/ladjs/superagent/blob/master/HISTORY.md)
- [Commits](https://github.com/ladjs/superagent/compare/v5.1.0...v5.3.1)
---
updated-dependencies:
- dependency-name: semver
dependency-type: indirect
- dependency-name: superagent
dependency-type: direct:production
...
Signed-off-by: dependabot[bot]
---
.../Asynchronous-Example/package-lock.json | 134 ++++++++++--------
.../Asynchronous-Example/package.json | 2 +-
2 files changed, 79 insertions(+), 57 deletions(-)
diff --git a/Asynchronous-JavaScript/Asynchronous-Example/package-lock.json b/Asynchronous-JavaScript/Asynchronous-Example/package-lock.json
index 3641dd5..7bd2b13 100644
--- a/Asynchronous-JavaScript/Asynchronous-Example/package-lock.json
+++ b/Asynchronous-JavaScript/Asynchronous-Example/package-lock.json
@@ -7,7 +7,7 @@
"asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
- "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
+ "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
},
"call-bind": {
"version": "1.0.2",
@@ -37,37 +37,37 @@
"integrity": "sha512-LDx6oHrK+PhzLKJU9j5S7/Y3jM/mUHvD/DeI1WQmJn652iPC5Y4TBzC9l+5OMOXlyTTA+SmVUPm0HQUwpD5Jqw=="
},
"debug": {
- "version": "4.1.1",
- "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz",
- "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==",
+ "version": "4.3.4",
+ "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
+ "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
"requires": {
- "ms": "^2.1.1"
+ "ms": "2.1.2"
}
},
"delayed-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
- "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk="
+ "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ=="
},
"fast-safe-stringify": {
- "version": "2.0.7",
- "resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.0.7.tgz",
- "integrity": "sha512-Utm6CdzT+6xsDk2m8S6uL8VHxNwI6Jub+e9NYTcAms28T84pTa25GJQV9j0CY0N1rM8hK4x6grpF2BQf+2qwVA=="
+ "version": "2.1.1",
+ "resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.1.1.tgz",
+ "integrity": "sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA=="
},
"form-data": {
- "version": "2.5.1",
- "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.5.1.tgz",
- "integrity": "sha512-m21N3WOmEEURgk6B9GLOE4RuWOFf28Lhh9qGYeNlGq4VDXUlJy2th2slBNU8Gp8EzloYZOibZJ7t5ecIrFSjVA==",
+ "version": "3.0.1",
+ "resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz",
+ "integrity": "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==",
"requires": {
"asynckit": "^0.4.0",
- "combined-stream": "^1.0.6",
+ "combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
}
},
"formidable": {
- "version": "1.2.1",
- "resolved": "https://registry.npmjs.org/formidable/-/formidable-1.2.1.tgz",
- "integrity": "sha512-Fs9VRguL0gqGHkXS5GQiMCr1VhZBxz0JnJs4JmMp/2jL18Fmbzvv7vOFRU+U8TBkHEE/CX1qDXzJplVULgsLeg=="
+ "version": "1.2.6",
+ "resolved": "https://registry.npmjs.org/formidable/-/formidable-1.2.6.tgz",
+ "integrity": "sha512-KcpbcpuLNOwrEjnbpMC0gS+X8ciDoZE1kkqzat4a8vrprf+s9pKNQ/QIwWfbfs4ltgmFl3MD177SNTkve3BwGQ=="
},
"function-bind": {
"version": "1.1.1",
@@ -75,12 +75,13 @@
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A=="
},
"get-intrinsic": {
- "version": "1.1.3",
- "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.3.tgz",
- "integrity": "sha512-QJVz1Tj7MS099PevUG5jvnt9tSkXN8K14dxQlikJuPt4uD9hHAHjLyLBiLR5zELelBdD9QNRAXZzsJx0WaDL9A==",
+ "version": "1.2.1",
+ "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.1.tgz",
+ "integrity": "sha512-2DcsyfABl+gVHEfCOaTrWgyt+tb6MSEGmKq+kI5HwLbIYgjgmMcV8KQ41uaKz1xxUcn9tJtgFbQUEVcEbd0FYw==",
"requires": {
"function-bind": "^1.1.1",
"has": "^1.0.3",
+ "has-proto": "^1.0.1",
"has-symbols": "^1.0.3"
}
},
@@ -92,6 +93,11 @@
"function-bind": "^1.1.1"
}
},
+ "has-proto": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.1.tgz",
+ "integrity": "sha512-7qE+iP+O+bgF9clE5+UoBFzE65mlBiVj3tKCrlNQ0Ogwm0BjpT/gK4SlLYDMybDh5I3TCTKnPPa0oMG7JDYrhg=="
+ },
"has-symbols": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz",
@@ -102,27 +108,35 @@
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
},
+ "lru-cache": {
+ "version": "6.0.0",
+ "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
+ "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
+ "requires": {
+ "yallist": "^4.0.0"
+ }
+ },
"methods": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz",
- "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4="
+ "integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w=="
},
"mime": {
- "version": "2.4.4",
- "resolved": "https://registry.npmjs.org/mime/-/mime-2.4.4.tgz",
- "integrity": "sha512-LRxmNwziLPT828z+4YkNzloCFC2YM4wrB99k+AV5ZbEyfGNWfG8SO1FUXLmLDBSo89NrJZ4DIWeLjy1CHGhMGA=="
+ "version": "2.6.0",
+ "resolved": "https://registry.npmjs.org/mime/-/mime-2.6.0.tgz",
+ "integrity": "sha512-USPkMeET31rOMiarsBNIHZKLGgvKc/LrjofAnBlOttf5ajRvqiRA8QsenbcooctK6d6Ts6aqZXBA+XbkKthiQg=="
},
"mime-db": {
- "version": "1.40.0",
- "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.40.0.tgz",
- "integrity": "sha512-jYdeOMPy9vnxEqFRRo6ZvTZ8d9oPb+k18PKoYNYUe2stVEBPPwsln/qWzdbmaIvnhZ9v2P+CuecK+fpUfsV2mA=="
+ "version": "1.52.0",
+ "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
+ "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg=="
},
"mime-types": {
- "version": "2.1.24",
- "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.24.tgz",
- "integrity": "sha512-WaFHS3MCl5fapm3oLxU4eYDw77IQM2ACcxQ9RIxfaC3ooc6PFuBMGZZsYpvoXS5D5QTWPieo1jjLdAm3TBP3cQ==",
+ "version": "2.1.35",
+ "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
+ "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
"requires": {
- "mime-db": "1.40.0"
+ "mime-db": "1.52.0"
}
},
"ms": {
@@ -131,22 +145,22 @@
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
},
"object-inspect": {
- "version": "1.12.2",
- "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.2.tgz",
- "integrity": "sha512-z+cPxW0QGUp0mcqcsgQyLVRDoXFQbXOwBaqyF7VIgI4TWNQsDHrBpUQslRmIfAoYWdYzs6UlKJtB2XJpTaNSpQ=="
+ "version": "1.12.3",
+ "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.3.tgz",
+ "integrity": "sha512-geUvdk7c+eizMNUDkRpW1wJwgfOiOeHbxBR/hLXK1aT6zmVSO0jsQcs7fj6MGw89jC/cjGfLcNOrtMYtGqm81g=="
},
"qs": {
- "version": "6.11.0",
- "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz",
- "integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==",
+ "version": "6.11.2",
+ "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.2.tgz",
+ "integrity": "sha512-tDNIz22aBzCDxLtVH++VnTfzxlfeK5CbqohpSqpJgj1Wg/cQbStNAz3NuqCs5vV+pjBsK4x4pN9HlVh7rcYRiA==",
"requires": {
"side-channel": "^1.0.4"
}
},
"readable-stream": {
- "version": "3.4.0",
- "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.4.0.tgz",
- "integrity": "sha512-jItXPLmrSR8jmTRmRWJXCnGJsfy85mB3Wd/uINMXA65yrnFo0cPClFIUWzo2najVNSl+mx7/4W8ttlLWJe99pQ==",
+ "version": "3.6.2",
+ "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz",
+ "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==",
"requires": {
"inherits": "^2.0.3",
"string_decoder": "^1.1.1",
@@ -154,14 +168,17 @@
}
},
"safe-buffer": {
- "version": "5.2.0",
- "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.0.tgz",
- "integrity": "sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg=="
+ "version": "5.2.1",
+ "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
+ "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ=="
},
"semver": {
- "version": "6.3.0",
- "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
- "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw=="
+ "version": "7.5.3",
+ "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.3.tgz",
+ "integrity": "sha512-QBlUtyVk/5EeHbi7X0fw6liDZc7BBmEaSYn01fMU1OUYbf6GPsbTtd8WmnqbI20SeycoHSeiybkE/q1Q+qlThQ==",
+ "requires": {
+ "lru-cache": "^6.0.0"
+ }
},
"side-channel": {
"version": "1.0.4",
@@ -182,27 +199,32 @@
}
},
"superagent": {
- "version": "5.1.0",
- "resolved": "https://registry.npmjs.org/superagent/-/superagent-5.1.0.tgz",
- "integrity": "sha512-7V6JVx5N+eTL1MMqRBX0v0bG04UjrjAvvZJTF/VDH/SH2GjSLqlrcYepFlpTrXpm37aSY6h3GGVWGxXl/98TKA==",
+ "version": "5.3.1",
+ "resolved": "https://registry.npmjs.org/superagent/-/superagent-5.3.1.tgz",
+ "integrity": "sha512-wjJ/MoTid2/RuGCOFtlacyGNxN9QLMgcpYLDQlWFIhhdJ93kNscFonGvrpAHSCVjRVj++DGCglocF7Aej1KHvQ==",
"requires": {
"component-emitter": "^1.3.0",
"cookiejar": "^2.1.2",
"debug": "^4.1.1",
- "fast-safe-stringify": "^2.0.6",
- "form-data": "^2.3.3",
- "formidable": "^1.2.1",
+ "fast-safe-stringify": "^2.0.7",
+ "form-data": "^3.0.0",
+ "formidable": "^1.2.2",
"methods": "^1.1.2",
- "mime": "^2.4.4",
- "qs": "^6.7.0",
- "readable-stream": "^3.4.0",
- "semver": "^6.1.1"
+ "mime": "^2.4.6",
+ "qs": "^6.9.4",
+ "readable-stream": "^3.6.0",
+ "semver": "^7.3.2"
}
},
"util-deprecate": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
- "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8="
+ "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw=="
+ },
+ "yallist": {
+ "version": "4.0.0",
+ "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
+ "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A=="
}
}
}
diff --git a/Asynchronous-JavaScript/Asynchronous-Example/package.json b/Asynchronous-JavaScript/Asynchronous-Example/package.json
index e5de3c6..b5b70ef 100644
--- a/Asynchronous-JavaScript/Asynchronous-Example/package.json
+++ b/Asynchronous-JavaScript/Asynchronous-Example/package.json
@@ -17,6 +17,6 @@
},
"homepage": "https://github.com/Lakshmangope/node.js#readme",
"dependencies": {
- "superagent": "^5.1.0"
+ "superagent": "^5.3.1"
}
}
From c34b09f9df6f1a2283578efbb529c612a4305be4 Mon Sep 17 00:00:00 2001
From: Lakshman Gope
Date: 2023年11月22日 12:29:09 +0600
Subject: [PATCH 42/56] Create output.js
---
Interview-Questions/output.js | 5 +++++
1 file changed, 5 insertions(+)
create mode 100644 Interview-Questions/output.js
diff --git a/Interview-Questions/output.js b/Interview-Questions/output.js
new file mode 100644
index 0000000..6ba076f
--- /dev/null
+++ b/Interview-Questions/output.js
@@ -0,0 +1,5 @@
+// 1) What is the output of 10+20+"30" in JavaScript?
+//Ans: 3030 because 10+20 will be 30. If there is numeric value before and after +, it treats as binary + (arithmetic operator).
+
+// 2) What is the output of "10"+20+30 in JavaScript?
+// Ans: 102030 because after a string all the + will be treated as string concatenation operator (not binary +).
From df85cf90b6cb8798de4c730ffbe99213a55e5a00 Mon Sep 17 00:00:00 2001
From: Lakshman Gope
Date: 2023年11月22日 23:11:39 +0600
Subject: [PATCH 43/56] Update output.js
---
Interview-Questions/output.js | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/Interview-Questions/output.js b/Interview-Questions/output.js
index 6ba076f..132ca0f 100644
--- a/Interview-Questions/output.js
+++ b/Interview-Questions/output.js
@@ -3,3 +3,20 @@
// 2) What is the output of "10"+20+30 in JavaScript?
// Ans: 102030 because after a string all the + will be treated as string concatenation operator (not binary +).
+
+// 3) Output?
+// Syncronous
+[1, 2, 3, 4].forEach((i) => {
+ console.log(i)
+})
+
+// Asynchronous
+function asyncForEach(array, cb) {
+ array.forEach(() => {
+ setTimeout(cb, 0);
+ })
+}
+
+asyncForEach([1, 2, 3, 4], (i) => {
+ console.log(i);
+})
From ec7592722c40a00f75f0eb31f43c67e5c85bb036 Mon Sep 17 00:00:00 2001
From: lgope
Date: 2023年11月24日 12:21:22 +0600
Subject: [PATCH 44/56] updated to es6
---
01 - JavaScript-Basics/Arrays.js | 8 ++++----
01 - JavaScript-Basics/Functions2.js | 2 +-
01 - JavaScript-Basics/emailValidate.js | 3 ++-
algorithms/binarySearchRecursive.js | 18 ++++++++----------
4 files changed, 15 insertions(+), 16 deletions(-)
diff --git a/01 - JavaScript-Basics/Arrays.js b/01 - JavaScript-Basics/Arrays.js
index 5462575..6813489 100644
--- a/01 - JavaScript-Basics/Arrays.js
+++ b/01 - JavaScript-Basics/Arrays.js
@@ -1,6 +1,6 @@
// Initialize new array
-var names = ['John', 'Mark', 'Jane'];
-var years = new Array(1990, 1969, 1948);
+let names = ['John', 'Mark', 'Jane'];
+let years = new Array(1990, 1969, 1948);
console.log(names[2]); // Jane
console.log(names.length); // 3
@@ -11,7 +11,7 @@ names[names.length] = 'Mary';
console.log(names);
// Different data types
-var john = ['John', 'Smith', 1990, 'designer', false];
+let john = ['John', 'Smith', 1990, 'designer', false];
john.push('blue'); // last input
john.unshift('Mr.'); // first input
@@ -25,5 +25,5 @@ console.log(john);
console.log(john.indexOf(23)); // -1 [because there is no such index.]
// Ternary Operator
-var isDesigner = john.indexOf('designer') === -1 ? 'John is NOT a designer' : 'John IS a designer';
+let isDesigner = john.indexOf('designer') === -1 ? 'John is NOT a designer' : 'John IS a designer';
console.log(isDesigner); // John IS a designer
\ No newline at end of file
diff --git a/01 - JavaScript-Basics/Functions2.js b/01 - JavaScript-Basics/Functions2.js
index 7ceb85c..23826cf 100644
--- a/01 - JavaScript-Basics/Functions2.js
+++ b/01 - JavaScript-Basics/Functions2.js
@@ -8,7 +8,7 @@
// Function expression
-var whatDoYouDo = function (job, firstName) {
+const whatDoYouDo = (job, firstName) => {
switch (job) {
case 'teacher':
return firstName + ' teaches kids how to code';
diff --git a/01 - JavaScript-Basics/emailValidate.js b/01 - JavaScript-Basics/emailValidate.js
index dc3934e..f5da06f 100644
--- a/01 - JavaScript-Basics/emailValidate.js
+++ b/01 - JavaScript-Basics/emailValidate.js
@@ -1,4 +1,5 @@
-function validateEmail(email) {
+// email regex
+const validateEmail = (email) => {
const re = /^(([^()\[\]\\.,;:\s@"]+(\.[^()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(String(email).toLowerCase());
}
diff --git a/algorithms/binarySearchRecursive.js b/algorithms/binarySearchRecursive.js
index 026430b..349b6d9 100644
--- a/algorithms/binarySearchRecursive.js
+++ b/algorithms/binarySearchRecursive.js
@@ -1,19 +1,17 @@
-function binarySearch(arr, val, start = 0, end = arr.length - 1) {
+const binarySearch = (arr, val, start = 0, end = arr.length - 1) => {
const mid = Math.floor((start + end) / 2);
- if (val === arr[mid]) {
- return mid;
- }
+ if (val === arr[mid]) return mid;
- if (start>= end) {
- return -1;
- }
+ if (start>= end) return -1;
return val < arr[mid] ? binarySearch(arr, val, start, mid - 1) : binarySearch(arr, val, mid + 1, end); -} +}; -let arr = [1, 2, 4, 6, 100, 10000]; +const arr = [1, 9, 5, 7, 2, 4, 8, 6].sort(); -console.log(binarySearch(arr, 2)); +const result = binarySearch(arr, 2); + +console.log(result !== -1 ? `Element is present at index ${result}` : 'Element is not present in array'); From 6b2f05b7f2c035f9004d2b9413a109d42e1dd334 Mon Sep 17 00:00:00 2001 From: lgope
Date: 2023年11月24日 14:22:35 +0600
Subject: [PATCH 45/56] es10 and output ques updated
---
ES10-or-ECMAScript2019/basicOfES10.js | 77 ++++++++++++++++++++++++---
1 file changed, 70 insertions(+), 7 deletions(-)
diff --git a/ES10-or-ECMAScript2019/basicOfES10.js b/ES10-or-ECMAScript2019/basicOfES10.js
index 9015bf9..98b2ee0 100644
--- a/ES10-or-ECMAScript2019/basicOfES10.js
+++ b/ES10-or-ECMAScript2019/basicOfES10.js
@@ -5,16 +5,16 @@ console.log(array.flat(2)); // [ 1, 2, 3, [ 4 ], [ 5 ] ]
// #2 Turning this array into a new array: [ 'Hello young grasshopper!', 'you are', 'learning fast!' ]
const greeting = [
- ['Hello', 'young', 'grasshopper!'],
- ['you', 'are'],
- ['learning', 'fast!']
+ ["Hello", "young", "grasshopper!"],
+ ["you", "are"],
+ ["learning", "fast!"],
];
-console.log(greeting.flatMap(x => x.join(' '))); // [ 'Hello young grasshopper!', 'you are', 'learning fast!' ]
+console.log(greeting.flatMap((x) => x.join(" "))); // [ 'Hello young grasshopper!', 'you are', 'learning fast!' ]
//#3 Turning the greeting array above into a string: 'Hello young grasshopper you are learning fast!'
-console.log(greeting.flatMap(x => x.join(' ')).join(' ')); // Hello young grasshopper! you are learning fast!
+console.log(greeting.flatMap((x) => x.join(" ")).join(" ")); // Hello young grasshopper! you are learning fast!
//#4 Turning the trapped 3 number into: [3]
const trapped = [[[[[[[[[[[[[[[[[[[[[[[[[[3]]]]]]]]]]]]]]]]]]]]]]]]]];
@@ -23,7 +23,7 @@ console.log(trapped.flat(Infinity)); // [ 3 ]
// Infintiy is actually a LARGE number in JavaScipt. It represents the maximum amount of memory that we can hold for a number! For more here: https://riptutorial.com/javascript/example/2337/infinity-and--infinity
//#5 Cleaning up this email to have no whitespaces. Make the answer be in a single line (return a new string):
-const userEmail3 = ' cannotfillemailformcorrectly@gmail.com ';
+const userEmail3 = " cannotfillemailformcorrectly@gmail.com ";
console.log(userEmail3.trimEnd().trimStart()); // cannotfillemailformcorrectly@gmail.com
@@ -34,9 +34,72 @@ const usersArray = Object.entries(users);
//#7 changing the output array of the above to have the user's IDs multiplied by 2 -- Should output:[ [ 'user1', 36546 ], [ 'user2', 185666 ], [ 'user3', 180630 ] ]
-updatedUsersArray = usersArray.map(user => [user[0], user[1] * 2]);
+updatedUsersArray = usersArray.map((user) => [user[0], user[1] * 2]);
//#8 changing the output array of #7 back into an object with all the users IDs updated to their new version. Should output: { user1: 36546, user2: 185666, user3: 180630 }
const updatedUsers = Object.fromEntries(updatedUsersArray);
console.log(updatedUsers); // { user1: 36546, user2: 185666, user3: 180630 }
+
+// Array.flat() && Array.flatMap
+const jobs = [
+ ["👮🏻", "💂🏻"],
+ ["👷🏻♂️", "🤴🏻"],
+];
+const flatJobs = jobs.flat(); // same as: const flatJobs = jobs.flat(1);
+
+console.log(flatJobs); // ['👮🏻', '💂🏻', '👷🏻♂️', '🤴🏻']
+
+const jobsList = [
+ ["👮🏻", "💂🏻"],
+ ["👷🏻♂️", "🤴🏻", ["🎅🏻", ["🦸🏻"], "🦹🏻♀️"]],
+];
+const flatJobsList = jobsList.flat(Infinity); // Infinity: flatten an array of arbitrary depth
+
+console.log(flatJobsList); // ['👮🏻', '💂🏻', '👷🏻♂️', '🤴🏻', '🎅🏻', '🦸🏻', '🦹🏻♀️']
+
+const names = ["police", "guard", "builder", "princess"];
+
+const mappedOnly = flatJobs.map((job, index) => [job, names[index]]);
+const mappedAndFlatten = flatJobs.flatMap((job, index) => [job, names[index]]);
+
+console.log(mappedOnly); // [['👮🏻', 'police'], ['💂🏻', 'guard'], ['👷🏻♂️', 'builder'], ['🤴🏻', 'princess']]
+console.log(mappedAndFlatten); // ['👮🏻', 'police', '💂🏻', 'guard', '👷🏻♂️', 'builder', '🤴🏻', 'princess']
+
+// From Entries
+const fruits = { lemon: "🍋", pineapple: "🍍", mango: "🥭", apple: "🍏" };
+const entries = Object.entries(fruits);
+
+console.log(Object.entries(fruits)); // [['lemon', '🍋'],['pineapple', '🍍'],['mango', '🥭'],['apple', '🍏']]
+console.log(Object.fromEntries(entries)); // {lemon: '🍋', pineapple: '🍍', mango: '🥭', apple: '🍏'}
+
+// String.trimStart() & String.trimEnd()
+const fruitsList = " 🥭🍏🍍 ";
+console.log(fruitsList.trimEnd()); // " 🥭🍏🍍";
+console.log(fruitsList.trimStart()); // "🥭🍏🍍 ";
+
+// Stable Array.prototype.sort()
+const fruitsArr = [
+ { name: "🥝", units: 12 },
+ { name: "🫐", units: 14 },
+ { name: "🍏", units: 16 },
+ { name: "🥬", units: 15 },
+ { name: "🍊", units: 18 },
+ { name: "🍐", units: 19 },
+];
+
+// Create our own sort criteria function:
+const sortCriteria = (fruit1, fruit2) => fruit1.units - fruit2.units;
+
+// Perform stable ES10 sort:
+const sorted = fruitsArr.sort(sortCriteria);
+
+console.log(sorted);
+// [
+// { name: "🥝", units: 12 },
+// { name: "🫐", units: 14 },
+// { name: "🥬", units: 15 },
+// { name: "🍏", units: 16 },
+// { name: "🍊", units: 18 },
+// { name: "🍐", units: 19 },
+// ];
From ee2c0aa305750f08694c4d68080d9d3f074fb73c Mon Sep 17 00:00:00 2001
From: lgope
Date: 2023年11月24日 14:24:25 +0600
Subject: [PATCH 46/56] es10 and output ques updated
---
.../Access-From-DOM/index.html | 11 ++++-
.../Access-From-DOM/scripts.js | 46 +++++++++---------
.../Access-From-DOM/shawon.jpg | Bin 93190 -> 0 bytes
Interview-Questions/output.js | 13 +++++
4 files changed, 46 insertions(+), 24 deletions(-)
delete mode 100644 DOM-Manipulation-And-Events/Access-From-DOM/shawon.jpg
diff --git a/DOM-Manipulation-And-Events/Access-From-DOM/index.html b/DOM-Manipulation-And-Events/Access-From-DOM/index.html
index 88704cc..28baa86 100644
--- a/DOM-Manipulation-And-Events/Access-From-DOM/index.html
+++ b/DOM-Manipulation-And-Events/Access-From-DOM/index.html
@@ -40,6 +40,15 @@ Article 003
asperiores odio est? Doloribus atque laborum pariatur fugit alias sunt possimus neque beatae,
unde dolorum nisi non minima!
+
+
+ Article 004
+ Lorem ipsum dolor sit amet consectetur adipisicing elit. Neque pariatur molestias minus. Quia
+ ullam voluptas laboriosam reprehenderit quisquam dolores dignissimos magni fuga dolor, animi
+ voluptatem temporibus maiores totam facere eum odit sint, consequatur eveniet inventore cum
+ officiis. At, sint voluptates exercitationem, quidem obcaecati id molestias cum dignissimos
+ velit possimus nisi.
+