Skip to content

Instantly share code, notes, and snippets.

@dgowrie
Last active September 14, 2019 07:01
Show Gist options
  • Save dgowrie/8a9c5c624a2c1d386c114724b3f659d0 to your computer and use it in GitHub Desktop.
Save dgowrie/8a9c5c624a2c1d386c114724b3f659d0 to your computer and use it in GitHub Desktop.
Higher Order Function - Simple Demo, web dev interview, discussion
<!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>
'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