Skip to content

Instantly share code, notes, and snippets.

@pbroschwitz
Last active February 11, 2017 08:43
Show Gist options
  • Save pbroschwitz/4038564376724a3798e1bcc7ad6a4e68 to your computer and use it in GitHub Desktop.
Save pbroschwitz/4038564376724a3798e1bcc7ad6a4e68 to your computer and use it in GitHub Desktop.
Pure functions / impure functions
<!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