Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

245
Views
No puedo entender cómo fluye la lógica de esta función de orden superior ES6

cómo fluye la lógica en: (libros) => (estantería) => ...

 const shelf1 = [ { name: "name1", shelf: "a" }, { name: "name2", shelf: "a" }, ]; const shelf2 = [ { name: "name3", shelf: "b" }, { name: "name4", shelf: "b" }, ]; const allBooks = [...shelf1, ...shelf2]; const filter = (books) => (shelf) => books.filter((b) => b.shelf === shelf); const filterBy = filter(allBooks); const booksOnShelf = filterBy("b");

necesito un equivalente más detallado a esta expresión abreviada, para ayudarme a digerir esa magia

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Es una función que acepta un argumento de books y devuelve una nueva función que acepta un argumento de shelf . Esa función se asigna a filterBy y el resultado de llamar a esa función (una matriz) se asigna a booksOnShelf .

La función interna mantiene una referencia a los books cuando se devuelve, y generalmente se denomina cierre .

 const shelf1=[{name:"name1",shelf:"a"},{name:"name2",shelf:"a"}],shelf2=[{name:"name3",shelf:"b"},{name:"name4",shelf:"b"}]; const allBooks = [...shelf1, ...shelf2]; function filter(books) { return function (shelf) { return books.filter(function (b) { return b.shelf === shelf; }); }; } // `filter` returns a new function which // is assigned to `filterBy`. That function accepts // a `shelf` argument const filterBy = filter(allBooks); // The result of calling that new function with // argument 'b' is assigned to `booksOnShelf` const booksOnShelf = filterBy('b'); console.log(booksOnShelf);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!