Created
January 10, 2018 14:27
-
-
Save ctrlShiftBryan/7fd6a091804010665ef6f22e7ea0986f to your computer and use it in GitHub Desktop.
Pure Functions.
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
//this is not a pure function because it has a 'hidden input' of the current date. | |
function addDay(days) { | |
var currentDate = new Date(); | |
return currentDate.setDate(currentDate.getDate() + days); | |
} | |
//this is not a pure function because it has a 'hidden output' of the times called. | |
var timesCalled = 0; | |
function addDay(days, currentDate) { | |
timesCalled = timesCalled + 1; | |
return currentDate.setDate(currentDate.getDate() + days); | |
} | |
//this is a pure function because it has no hidden inputs or outputs. | |
function addDays(days, currentDate, timesCalled) { | |
return [currentDate.setDate(currentDate.getDate() + days), timesCalled + 1] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment