Skip to content

Instantly share code, notes, and snippets.

@ctrlShiftBryan
Created January 10, 2018 14:27
Show Gist options
  • Save ctrlShiftBryan/7fd6a091804010665ef6f22e7ea0986f to your computer and use it in GitHub Desktop.
Save ctrlShiftBryan/7fd6a091804010665ef6f22e7ea0986f to your computer and use it in GitHub Desktop.
Pure Functions.
//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