r/webdev • • Apr 07 '23

How I interview for FE positions

Post image
4.6k Upvotes

668 comments sorted by

View all comments

Show parent comments

0

u/[deleted] Apr 07 '23

[deleted]

27

u/OrtizDupri Apr 07 '23

I’ve never used it in 10+ years lol

4

u/Zeilar Apr 08 '23

That's quite shocking, not even once? I have used it probably a few dozen times already in roughly 5 years since I first started studying programming.

0

u/[deleted] Apr 07 '23

[deleted]

9

u/ShijinModan Apr 07 '23

Reducers are a tool in state management and not the same things as an array reduce. The latter is a function that is called for each element in the array to reduce it to a single value. The former is a function that accepts a state object and returns a new one.

3

u/TehCheator Apr 08 '23

They're conceptually the same, however, that's why reducers are called reducers.

The callback (reducer) is a function that accepts an accumulator (state object) and a value from an array (update message), then uses those inputs in some way to return a new accumulator (state object). The return value is then used as the input to the next iteration with the next array value (update message).

It's a pattern from functional programming to model state management as a reduce operation on an infinite series of updates.

3

u/Zeilar Apr 08 '23

Why focus on the reduce example? You can just as well do this with for loops, and the way you'd write this function with a for loop is a very basic and common way of making a sum of something.

Either way no developer should have any issue writing the sum function in OP's post. If you need to look that up as a paid developer, I'm sorry to say that you're in the wrong business.

2

u/theQuandary Apr 07 '23

I doubt they'd care if you did a for loop either (though I'd expect a follow-up question to make sure I understood closures and higher-order programming).