You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<ahref="https://codepen.io/Bunlong/pen/JBJWRa"target="_blank">Edit on Codepen</a>
96
96
97
+
## Pure Functions
98
+
99
+
A function that given the same input, will always return the same output. A pure function produces no side effects.
100
+
101
+
Note: Side effects may include:
102
+
103
+
* changing the file system
104
+
* inserting a record into a database
105
+
* making an http call
106
+
* mutations
107
+
* printing to the screen / logging
108
+
* obtaining user input
109
+
* querying the DOM
110
+
* accessing system state
111
+
112
+
```javascript
113
+
var xs = [1, 2, 3, 4, 5];
114
+
115
+
// ==== pure ====
116
+
xs.slice(0, 3);
117
+
//=> [1, 2, 3]
118
+
119
+
xs.slice(0, 3);
120
+
//=> [1, 2, 3]
121
+
122
+
xs.slice(0, 3);
123
+
//=> [1, 2, 3]
124
+
125
+
// ==== pure ====
126
+
xs.splice(0, 3);
127
+
//=> [1, 2, 3]
128
+
129
+
xs.splice(0, 3);
130
+
//=> [4, 5]
131
+
132
+
xs.splice(0, 3);
133
+
//=> []
134
+
135
+
// pure
136
+
varcheckAge=function(age) {
137
+
var minimum =21;
138
+
return age >= minimum;
139
+
};
140
+
141
+
// impure
142
+
var minimum =21;
143
+
144
+
varcheckAge=function(age) {
145
+
return age >= minimum;
146
+
};
147
+
```
148
+
97
149
## Currying
98
150
99
151
Currying allows a function with multiple arguments to be translated into a sequence of functions. Curried functions can be tailored to match the signature of another function.
0 commit comments