Last active
June 24, 2017 12:59
-
-
Save robinpokorny/3cf91b132a80e1e84d4b2d294745b994 to your computer and use it in GitHub Desktop.
Which of these functions are pure? https://medium.com/@robinpokorny/do-pure-functions-exist-in-javascript-b128ed5f0ed2
This file contains hidden or 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
// A: Simple multiplication | |
function doubleA(n) { | |
return n * 2 | |
} | |
// B: With a variable | |
var two = 2 | |
function doubleB(n) { | |
return n * two | |
} | |
// C: With a helper function | |
function getTwo() { | |
return 2 | |
} | |
function doubleC(n) { | |
return n * getTwo() | |
} | |
// D: Mapping an array | |
function doubleD(arr) { | |
return arr.map(n => n * 2) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment