Skip to content

Commit 31a1e85

Browse files
committed
Use 'const' instead of 'let'
1 parent 7d26a3c commit 31a1e85

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

README.md

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ Returns the same result given same parameters. It's execution doesn't depend on
1717
1) Impure
1818

1919
```javascript
20-
let number = 1;
20+
const number = 1;
2121

22-
let increment = () => number += 1;
22+
const increment = () => number += 1;
2323

2424
increment();
2525
// 2
@@ -28,7 +28,7 @@ increment();
2828
2) Pure
2929

3030
```javascript
31-
let increment = n => n + 1;
31+
const increment = n => n + 1;
3232

3333
increment(1);
3434
// 2
@@ -40,9 +40,9 @@ Functions that operate on other functions, either by taking them as arguments or
4040
1) Sum
4141

4242
```javascript
43-
let sum = (x, y) => x + y;
43+
const sum = (x, y) => x + y;
4444

45-
let calculate = (fn, x, y) => fn(x, y);
45+
const calculate = (fn, x, y) => fn(x, y);
4646

4747
calculate(sum, 1, 2);
4848
// 3
@@ -51,13 +51,13 @@ calculate(sum, 1, 2);
5151
2) Filter
5252

5353
```javascript
54-
let students = [
54+
const students = [
5555
{name: 'Anna', grade: 6},
5656
{name: 'John', grade: 4},
5757
{name: 'Maria', grade: 9}
5858
];
5959

60-
let isApproved = student => student.grade >= 6;
60+
const isApproved = student => student.grade >= 6;
6161

6262
students.filter(isApproved);
6363
// [ { name: 'Anna', grade: 6 }, { name: 'Maria', grade: 9 } ]
@@ -66,7 +66,7 @@ students.filter(isApproved);
6666
3) Map
6767

6868
```javascript
69-
let byName = obj => obj.name;
69+
const byName = obj => obj.name;
7070

7171
students.map(byName);
7272
// [ 'Anna', 'John', 'Maria' ]
@@ -75,15 +75,15 @@ students.map(byName);
7575
4) Chaining
7676

7777
```javascript
78-
let students = [
78+
const students = [
7979
{name: 'Anna', grade: 6},
8080
{name: 'John', grade: 4},
8181
{name: 'Maria', grade: 9}
8282
];
8383

84-
let isApproved = student => student.grade >= 6;
84+
const isApproved = student => student.grade >= 6;
8585

86-
let byName = obj => obj.name;
86+
const byName = obj => obj.name;
8787

8888
students.filter(isApproved).map(byName);
8989
// ['Anna', 'Maria']
@@ -92,7 +92,7 @@ students.filter(isApproved).map(byName);
9292
5) Reduce
9393

9494
```javascript
95-
let totalGrades = students.reduce((sum, student) => sum + student.grade, 0);
95+
const totalGrades = students.reduce((sum, student) => sum + student.grade, 0);
9696

9797
totalGrades
9898
// 19
@@ -104,7 +104,7 @@ Whenever a function calls itself, creating a loop.
104104
1) Countdown
105105

106106
```javascript
107-
let countdown = num => {
107+
const countdown = num => {
108108
if (num > 0) {
109109
console.log(num);
110110
countdown(num - 1);
@@ -124,7 +124,7 @@ countdown(5);
124124
2) Factorial
125125

126126
```javascript
127-
let factorial = num => {
127+
const factorial = num => {
128128
if (num <= 0) {
129129
return 1;
130130
} else {
@@ -142,9 +142,9 @@ Given a value and a function, unwraps the values to get to its inner value(s), c
142142
1) Adding a value to all the elements in a array
143143

144144
```javascript
145-
let plus1 = num => num + 1;
145+
const plus1 = num => num + 1;
146146

147-
let numbers = [1, 2, 3];
147+
const numbers = [1, 2, 3];
148148
numbers.map(plus1);
149149
// [2, 3, 4]
150150
```
@@ -155,12 +155,12 @@ The composition of two or more functions returns a new function.
155155
1) Combining two functions to generate another one
156156

157157
```javascript
158-
let compose = (f,g) => x => f(g(x));
158+
const compose = (f,g) => x => f(g(x));
159159

160-
let toUpperCase = function(x) { return x.toUpperCase(); };
161-
let exclaim = function(x) { return x + '!'; };
160+
const toUpperCase = function(x) { return x.toUpperCase(); };
161+
const exclaim = function(x) { return x + '!'; };
162162

163-
let angry = compose(exclaim, toUpperCase);
163+
const angry = compose(exclaim, toUpperCase);
164164

165165
angry("stop this");
166166
// STOP THIS!
@@ -169,13 +169,13 @@ angry("stop this");
169169
2) Combining three functions to generate another one
170170

171171
```javascript
172-
let compose = (f,g) => x => f(g(x));
172+
const compose = (f,g) => x => f(g(x));
173173

174-
let toUpperCase = function(x) { return x.toUpperCase(); };
175-
let exclaim = function(x) { return x + '!'; };
176-
let moreExclaim = function(x) { return x + '!!!!!'; };
174+
const toUpperCase = function(x) { return x.toUpperCase(); };
175+
const exclaim = function(x) { return x + '!'; };
176+
const moreExclaim = function(x) { return x + '!!!!!'; };
177177

178-
let reallyAngry = compose(exclaim, (toUpperCase, moreExclaim));
178+
const reallyAngry = compose(exclaim, (toUpperCase, moreExclaim));
179179

180180
reallyAngry("stop this");
181181
// STOP THIS!!!!!!
@@ -187,25 +187,25 @@ Extract data from arrays or objects using a syntax that mirrors the construction
187187
1) Select from pattern
188188

189189
```javascript
190-
let foo = () => [1, 2, 3];
190+
const foo = () => [1, 2, 3];
191191

192-
let [a, b] = foo();
192+
const [a, b] = foo();
193193
console.log(a, b);
194194
// 1 2
195195
```
196196

197197
2) Accumulates the rest values
198198

199199
```javascript
200-
let [a, ...b] = [1, 2, 3];
200+
const [a, ...b] = [1, 2, 3];
201201
console.log(a, b);
202202
// 1 [2, 3]
203203
```
204204

205205
3) Optional parameters
206206

207207
```javascript
208-
let ajax = function ({ url = "localhost", port: p = 80}, ...data) {
208+
const ajax = function ({ url = "localhost", port: p = 80}, ...data) {
209209
console.log("Url:", url, "Port:", p, "Rest:", data);
210210
};
211211

@@ -222,7 +222,7 @@ Taking a function that takes multiple arguments and turning it into a chain of f
222222
1) Currying an Object
223223

224224
```javascript
225-
let student = name => grade => `Name: ${name} | Grade: ${grade}`;
225+
const student = name => grade => `Name: ${name} | Grade: ${grade}`;
226226

227227
student("Matt")(8);
228228
// Name: Matt | Grade: 8
@@ -231,10 +231,10 @@ student("Matt")(8);
231231
2) Currying a Sum
232232

233233
```javascript
234-
let add = x => y => x + y;
234+
const add = x => y => x + y;
235235

236-
let increment = add(1);
237-
let addFive = add(5);
236+
const increment = add(1);
237+
const addFive = add(5);
238238

239239
increment(3);
240240
//4

0 commit comments

Comments
 (0)