Created
October 2, 2017 23:42
-
-
Save adeyahya/f8e6cc069c712a1b59f308a1cee441c1 to your computer and use it in GitHub Desktop.
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
const curry = require('lodash/curry') | |
const match = curry(function(what, str) { | |
return str.match(what) | |
}) | |
const replace = curry(function(what, replacement, str) { | |
return str.replace(what, replacement) | |
}) | |
const filter = curry(function(fn, ary) { | |
return ary.filter(fn) | |
}) | |
const map = curry(function(fn, ary) { | |
return ary.map(fn) | |
}) | |
// composing | |
const hasSpace = match(/\s+/g) | |
hasSpace('hello world') | |
// [''] | |
hasSpace('spaceless') | |
// null | |
const findSpace = filter(hasSpace) | |
findSpace(['hello world','hello_world','helo bandung','hello_bandung']) | |
// ['hello world', 'hello bandung'] | |
const noVowels = replace(/[aiueoy]/ig) | |
const cencored = noVowels("*") | |
cencored('hello world') | |
// h*ll* w*rld |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment