Skip to content

Commit f7700f9

Browse files
committed
Merge branch 'master' of https://github.com/lgope/JavaScript
2 parents ec75927 + df85cf9 commit f7700f9

23 files changed

Lines changed: 844 additions & 54 deletions

05 - Objects-And-Functions/recursiveFunction.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,14 @@ var factorial = function (number) {
4343
};
4444

4545
console.log(`Factorial = ${factorial(9)}`);
46+
47+
48+
// Function
49+
function countDown(number) {
50+
if (number !== 0) countDown.count += number + countDown(number - 1);
51+
return countDown.count;
52+
}
53+
54+
countDown.count = 0;
55+
console.log(countDown(4));
56+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const arr = [{
2+
name: 'xyz',
3+
grade: 'xs'
4+
}, {
5+
name: 'yaya',
6+
grade: 'xa'
7+
}, {
8+
name: 'xf',
9+
frade: 'dd'
10+
}, {
11+
name: 'a',
12+
grade: 'b'
13+
}];
14+
15+
16+
function filterIt(arr, searchKey) {
17+
return arr.filter(obj => Object.keys(obj).some(key => obj[key].includes(searchKey)));
18+
}
19+
20+
console.log("find 'x'", filterIt(arr,"x"));
21+
console.log("find 'a'", filterIt(arr,"a"));
22+
console.log("find 'z'", filterIt(arr,"z"));

Array/removeDuplicates.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const fruits = ['🥑', '🍊', '🍇', '🍏', '🍎', '🍑', '🍑'];
2+
3+
// way 1
4+
console.log('way 1 ', fruits.reduce((uniqueArray, fruit) => {
5+
uniqueArray.indexOf(fruit) === -1 && uniqueArray.push(fruit);
6+
return uniqueArray;
7+
}, []))
8+
9+
// way 2
10+
console.log('way 2 ', fruits.filter((fruit, index) => fruits.indexOf(fruit) === index))
11+
12+
// way 3
13+
console.log('way 3 ', [...new Set(fruits)])

Asynchronous-JavaScript/Asynchronous-Example/package-lock.json

Lines changed: 129 additions & 52 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Asynchronous-JavaScript/Asynchronous-Example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
},
1818
"homepage": "https://github.com/Lakshmangope/node.js#readme",
1919
"dependencies": {
20-
"superagent": "^5.1.0"
20+
"superagent": "^5.3.1"
2121
}
2222
}

Asynchronous-JavaScript/byeTryCatchErrorHandling.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,23 @@ exports.createOne = Model =>
4444
},
4545
});
4646
});
47+
48+
// another
49+
50+
const awaitHandlerFactory = (middleware) => {
51+
return async (req, res, next) => {
52+
try {
53+
await middleware(req, res, next);
54+
} catch (err) {
55+
next(err);
56+
}
57+
};
58+
};
59+
// and use it this way:
60+
app.get(
61+
"/",
62+
awaitHandlerFactory(async (request, response) => {
63+
const result = await getContent();
64+
response.send(result);
65+
})
66+
);

BuildIn-Methods/toFixed.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const fixNum = (num, n = 2) => Number.parseFloat(num).toFixed(n);
2+
3+
console.log(fixNum(123.456));
4+
// expected output: "123.46"
5+
6+
console.log(fixNum(0.004));
7+
// expected output: "0.00"
8+
9+
console.log(fixNum('1.23e+5', 4));
10+
// expected output: "123000.0000"

0 commit comments

Comments
 (0)