Last active
February 11, 2017 08:43
-
-
Save pbroschwitz/4038564376724a3798e1bcc7ad6a4e68 to your computer and use it in GitHub Desktop.
Pure functions / impure functions
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Pure functions</title> | |
</head> | |
<body> | |
<p>Reference: <a href="https://egghead.io/lessons/javascript-redux-pure-and-impure-functions">Egghead</a></p> | |
<script id="jsbin-javascript"> | |
// Pure functions | |
"use strict"; | |
function square(x) { | |
return x * x; | |
} | |
function squareAll(items) { | |
return items.map(square); | |
} | |
// Impure functions | |
function square(x) { | |
updateXInDatabase(x); | |
return x * x; | |
} | |
function squareAll(items) { | |
for (var i = 0; i < items.length; i++) { | |
items[i] = square(items[i]); | |
} | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment