Skip to content

Commit 597b110

Browse files
author
krishna9802
committed
added new snippets
1 parent 9175042 commit 597b110

File tree

1 file changed

+70
-7
lines changed

1 file changed

+70
-7
lines changed

README.md

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,51 @@ One liner clean code snippets in javascript/react with ES6 syntax
88

99
### Table of Contents
1010

11-
| No. | Code |
11+
| No. | Code | |
1212
| --- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
13-
| 1 | [Add a key-value pair in object conditionally](#add-a-key-value-pair-in-object-conditionally) |
14-
| 2 | [Deleting a particular key from object](#deleting-a-particular-key-from-object) |
13+
14+
| 1 | [Conditional statement]
15+
(#conditional-statement)
16+
|
17+
| 2 | [Add a key-value pair in object conditionally](#add-a-key-value-pair-in-object-conditionally) |
18+
| 3 | [Deleting a particular key from object](#deleting-a-particular-key-from-object) |
19+
| 4 | [filling-array-with-dummy-values](#deleting-a-particular-key-from-object) |
1520

1621

1722
---
1823

1924

20-
1. ### Add a key-value pair in object conditionally
25+
1. ### Conditional Statement
26+
27+
28+
29+
**Plain conditional operation**
30+
31+
```javascript
32+
const is_employee=true;
33+
let company
34+
if(is_employee){
35+
company='Inventives.ai';
36+
}
37+
else{
38+
company=null;
39+
}
40+
```
41+
42+
43+
- We will use Ternary operator
44+
45+
```javascript
46+
const is_employee=true;
47+
let company = is_employee?company='Inventives.ai':company=null;
48+
```
49+
50+
**[⬆ Back to Top](#table-of-contents)**
51+
52+
53+
54+
55+
2. ### Add a key-value pair in object conditionally
2156

2257
**Plain conditional operation**
2358

@@ -73,10 +108,8 @@ One liner clean code snippets in javascript/react with ES6 syntax
73108

74109

75110

76-
2. ### Deleting a particular key from object
77-
111+
3. ### Deleting a particular key from object
78112

79-
80113
**Plain conditional operation**
81114

82115
```javascript
@@ -112,6 +145,36 @@ One liner clean code snippets in javascript/react with ES6 syntax
112145

113146

114147
- More code snippets are being added
148+
149+
150+
4. ### Filling array with dummy values
151+
152+
153+
154+
**Plain conditional operation**
155+
156+
```javascript
157+
const arr_length=6;
158+
for(let i=0;i<arr_length;i++){
159+
dummyArr[i] {'written_by' : 'Krishna Kant'};
160+
}
161+
```
162+
163+
164+
- We will use Array instance with Higher Order Function--> array.map()
165+
166+
```javascript
167+
168+
const arr_length=6;
169+
let dummyArr = new Array(arr_length).fill(null).map(()=>({'written_by' : 'Krishna Kant'}));
170+
```
171+
172+
**[⬆ Back to Top](#table-of-contents)**
173+
174+
175+
176+
177+
115178
## Disclaimer
116179

117180
The code snippets mentioned in this repository are the summary of frequently used codes in Javascript and/or React with ES6 syntax. We cannot guarantee that only these snippets will actually make the code cleaner, smoother and optimised, nor should you focus on copying and pasting them all. The primary purpose is for you to get a sense of how some bulk codes might be replaced with one-liner ES6 conditional and operational statements!

0 commit comments

Comments
 (0)