Last active
May 2, 2017 08:09
-
-
Save kishanio/b5489b12c7043cc277ef0be341977e67 to your computer and use it in GitHub Desktop.
Redux : Pure vs Impure Function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Pure Function | |
function square(x) { | |
return x * x; | |
} | |
function squareAll(items) { | |
return items.map(square); | |
} | |
// Impure Function | |
function squareAllImpure(items){ | |
for (let i = 0; i < items.length; i++) { | |
items[i] = square(items[i]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment