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)

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay