Created
September 11, 2017 17:54
-
-
Save balintsera/7e5a83fa1890b68ecbf058e6ae9e9a20 to your computer and use it in GitHub Desktop.
higher order function created by balintsera - https://repl.it/Kwbw/1
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
var snakify = function(text) { | |
return text.replace(/millenials/ig, "Snake People"); | |
}; | |
console.log(snakify("The Millenials are always up to something.")); | |
var hippify = function(text) { | |
return text.replace(/baby boomers/ig, "Aging Hippies"); | |
}; | |
console.log(hippify("The Baby Boomers just look the other way.")); | |
// Higher order: function returns function | |
var attitude = function(original, replacement) { | |
return function(source) { | |
return source.replace(original, replacement); | |
}; | |
}; | |
var snakify = attitude(/millenials/ig, "Snake People"); | |
var hippify = attitude(/baby boomers/ig, "Aging Hippies"); | |
console.log(snakify("The Millenials are always up to something.")); | |
console.log(hippify("The Baby Boomers just look the other way.")); | |
// original: https://www.sitepoint.com/higher-order-functions-javascript/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment