over engineered reduce
Peter Vivo

Peter Vivo @pengeszikra

About: Pipeline operator and touch bar fanatic from Hungary. God speed you!

Location:
Pomaz
Joined:
Jul 24, 2020

over engineered reduce

Publish Date: Jan 28 '22
0 0

Try to interpret this code:



  const [,startOfPP,,log] = jobList.reduce(
    ([acu, pp, prev, ppPrev], cur) => 
      [
        [...acu, cur]
        , 
        cur.type === EVENT_TYPE.postProcess && prev.type !== EVENT_TYPE.postProcess
          ? cur
          : pp
        , 
        cur
        ,
        [...ppPrev, [pp, prev, cur]]
      ]
    , [[], null , {}, []]);


Enter fullscreen mode Exit fullscreen mode

At this moment I sad STOP! That is carzy! The base idea was I wrote a single pure reducer, which is give back startOfPP value and log. So I started 4 variable in local state: [[],

null , {}, []]

, but after take look back to code, I found this over engineered reducer solution.

Comments 0 total

    Add comment