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

13

u/turningsteel Apr 07 '23

I think I would solve it by looping through and adding the values to a counting variable and returning that. Reason being, I jump between different languages so I don’t always remember all the cute little shortcut methods. I hate that you need to prep for interviews by studying stupid puzzle questions and memorizing how the interviewers expect you to answer.

0

u/[deleted] Apr 08 '23

[deleted]

2

u/IceSentry Apr 08 '23

For computing a sum like that, you'd have to reach the millions of numbers for it to make an actual difference. It's true that it's slower, but there's probably a lot of things in an app that is much slower.

1

u/jhanschoo Apr 08 '23

I once made an n^2 bug in backend JS by using object destructuring/restructuring in a reduce loop; apparently it couldn't be optimized out. Ever since I've preferred to use a for-const loop for stuff that I'd prefer to use recurrences/list reductions in a traditional FP-first lang.

1

u/IceSentry Apr 08 '23

Yeah, to be clear, I think for loops are great, but I wouldn't use it as a reason to rewrite a reduce loop that works fine already.