Home
← All questions

Implement pipe and compose in JavaScript

EasyPremiumJavaScript

Asked at Tekion

JavaScript interview practice: pipe runs functions left-to-right; compose runs them right-to-left, threading the result through each.

Problem

  • pipe(...fns)(x) applies the functions from left to right.
  • compose(...fns)(x) applies them from right to left.
function pipe(...fns) {
  // your code
}
function compose(...fns) {
  // your code
}
Premium question

Unlock the in-browser editor, test cases, and model solution with Mentoxis Premium.

Unlock with Premium