Skip to content

Instantly share code, notes, and snippets.

@adeyahya
Created October 2, 2017 23:42
Show Gist options
  • Save adeyahya/f8e6cc069c712a1b59f308a1cee441c1 to your computer and use it in GitHub Desktop.
Save adeyahya/f8e6cc069c712a1b59f308a1cee441c1 to your computer and use it in GitHub Desktop.
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