Last active
September 14, 2019 07:01
-
-
Save dgowrie/8a9c5c624a2c1d386c114724b3f659d0 to your computer and use it in GitHub Desktop.
Higher Order Function - Simple Demo, web dev interview, discussion
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="Higher Order Function - Simple Demo"> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
'use strict'; | |
var snakify = function snakify(text) { | |
return text.replace(/millenials/ig, 'Snake People'); | |
}; | |
console.log(snakify('The millenials are up to no good')); | |
var hippify = function hippify(text) { | |
return text.replace(/baby boomers/ig, 'Aging Hippies'); | |
}; | |
console.log(hippify('The baby boomers just look the other way.')); | |
var attitude = function attitude(input, adjustment) { | |
return function (text) { | |
return text.replace(/input/ig, adjustment); | |
}; | |
}; | |
var snakify2 = attitude('millenials', 'Snake People'); | |
var hippify2 = attitude('baby boomers', 'Aging Hippies'); | |
console.log(snakify2('The millenails are STILL up to no good.')); | |
console.log(hippify2('The baby boomers STILL just look the other way.')); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">const snakify = text => text.replace(/millenials/ig, 'Snake People'); | |
console.log(snakify('The millenials are up to no good')); | |
const hippify = text => text.replace(/baby boomers/ig, 'Aging Hippies'); | |
console.log(hippify('The baby boomers just look the other way.')); | |
const attitude = (input, adjustment) => text => text.replace(/input/ig, adjustment); | |
const snakify2 = attitude('millenials', 'Snake People'); | |
const hippify2 = attitude('baby boomers', 'Aging Hippies'); | |
console.log(snakify2('The millenails are STILL up to no good.')); | |
console.log(hippify2('The baby boomers STILL just look the other way.'));</script></body> | |
</html> |
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
'use strict'; | |
var snakify = function snakify(text) { | |
return text.replace(/millenials/ig, 'Snake People'); | |
}; | |
console.log(snakify('The millenials are up to no good')); | |
var hippify = function hippify(text) { | |
return text.replace(/baby boomers/ig, 'Aging Hippies'); | |
}; | |
console.log(hippify('The baby boomers just look the other way.')); | |
var attitude = function attitude(input, adjustment) { | |
return function (text) { | |
return text.replace(/input/ig, adjustment); | |
}; | |
}; | |
var snakify2 = attitude('millenials', 'Snake People'); | |
var hippify2 = attitude('baby boomers', 'Aging Hippies'); | |
console.log(snakify2('The millenails are STILL up to no good.')); | |
console.log(hippify2('The baby boomers STILL just look the other way.')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment