Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

314
Vistas
How to implement pipe function with arg AND ...funcs?
const replaceUnderscoreWithSpace = (value) => value.replace(/_/g, ' ')
const capitalize = (value) =>
    value
        .split(' ')
        .map((val) => val.charAt(0).toUpperCase() + val.slice(1))
        .join(' ');
const appendGreeting = (value) => `Hello, ${value}!`

const pipe = (value, ...funcs) => value => funcs.reduce((value, f) => f(value), value)

I`m trying to implement pipe function, but I can`t get how to make it work so it takes param "value" as argument.

Example

const result = pipe(
  "john_doe",
  replaceUnderscoreWithSpace,
  capitalize,
  appendGreeting,
);
 
alert(result); // Hello, John Doe!
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You have an extra nested function in your pipe() implementation. So pipe() returns a function that calls reduce() rather than calling reduce() itself.

Get rid of value =>.

const replaceUnderscoreWithSpace = (value) => value.replace(/_/g, ' ')
const capitalize = (value) =>
    value
        .split(' ')
        .map((val) => val.charAt(0).toUpperCase() + val.slice(1))
        .join(' ');
const appendGreeting = (value) => `Hello, ${value}!`

const pipe = (value, ...funcs) => funcs.reduce((value, f) => f(value), value);

const result = pipe(
  "john_doe",
  replaceUnderscoreWithSpace,
  capitalize,
  appendGreeting,
);
 
console.log(result); // Hello, John Doe!

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda