<div id="root"></div>
// this is just here to display results to DOM
const addResultToDOM = (...args) => $('#root').append(`<div>${args.join(' ')}</div>`)

const compose = (...fns) => arg => fns.reduce((acc, fn) => fn(acc), arg)

const curry = (uncurriedFn, ...args) => {
  // you can get the arity of a function by calling length on the fn
  const arity = uncurriedFn.length 
  
  const accumulator = (...accArgs) => {
    let argsCopy = [...args] // 
    if (accArgs.length > 0) {
      argsCopy = [...argsCopy, ...accArgs]
    }

    if (args.length >= arity) return uncurriedFn.apply(null, argsCopy)
    return curry.apply(null, [uncurriedFn, ...argsCopy]) // recurse
  }
  // if any args passed in, pass them to the accumulator
  return args.length >= arity ? accumulator() : accumulator
}

const nums = [1, 2, 3, 4, 5]
const evenNums = nums.filter(num => num % 2 === 0)

evenNums.map(i => addResultToDOM(i)) // Just to show

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/lodash-fp/0.10.4/lodash-fp.min.js
  2. https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js