DEV Community

Peter Vivo
Peter Vivo

Posted on

over engineered reduce

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.

Top comments (0)