Skip to content

Instantly share code, notes, and snippets.

@lumixraku
Last active September 11, 2020 16:01
Show Gist options
  • Save lumixraku/cb75e091b9e16e41acc6cdd919060665 to your computer and use it in GitHub Desktop.
Save lumixraku/cb75e091b9e16e41acc6cdd919060665 to your computer and use it in GitHub Desktop.

Revisions

  1. lumixraku revised this gist Sep 11, 2020. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion curry.js
    Original file line number Diff line number Diff line change
    @@ -10,4 +10,8 @@ const curring = fn => {

    const listMerge = (a, b, c) => [a, b, c]
    const curried = curring(listMerge)
    console.log(curried(1)(2)(3)) // [1, 2, 3]
    console.log(curried(1)(2)(3)) // [1, 2, 3]

    console.log(curried(1, 2)(3)) // [1, 2, 3]

    console.log(curried(1, 2, 3)) // [1, 2, 3]
  2. lumixraku created this gist Sep 11, 2020.
    13 changes: 13 additions & 0 deletions curry.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    const curring = fn => {
    const { length } = fn
    const curried = (...args) => {
    return (args.length >= length
    ? fn(...args)
    : (...args2) => curried(...args.concat(args2)))
    }
    return curried
    }

    const listMerge = (a, b, c) => [a, b, c]
    const curried = curring(listMerge)
    console.log(curried(1)(2)(3)) // [1, 2, 3]