For loops versus map/filter/reduce functions

I’m working through the Javascript Algorithms And Data Structures Certification. I’m stumbling on the advantage of map, filter and reduce functions over the use of for loops. I’ll spend 30 minutes on the functional programming challenges that disallow for loops and five minutes on the later challenges allowing for loops.

Will the use of for loops instead of built in functions cause a potential employer to pass a candidate over?

Do the professionals use these built in functions instead of commenting on what they’re trying to accomplish?

Do the built in functions have any significant advantage on a webpage?

I found an article touting the benefits at https://medium.com/front-end-hacking/stop-array-foreach-and-start-using-filter-map-some-reduce-functions-298b4dabfa09.

I’ll be polite and agree to disagree on the claims until I’m more experienced.

Agreeing with Randy, sometimes the prototype methods are easier and cleaner. When I see a map or reduce or sort method, I instantly have an idea of what it is trying to do and a quick look at the callback tells me how. If it is buried in a for loop, then I have to take a second to figure it out.

There certainly are cases where a for loop is better. But all things being equal, prototype methods are usually better if you have a choice.

So yes, I if I were interviewing someone and they needed to add up all the numbers in an array, and they didn’t use reduce, it would make me wonder how well they know JS. Would be be passed over? Maybe, maybe not. But you would probably loose points for it.

Sometimes one is better and sometimes the other is. The ability to tell the difference comes from experience. If you don’t know which is better, then you lack that experience.

I recently had a coding interview where I started to use a for loop and then almost immediately switched to a while loop. When the person was evaluating me, he commented that I should have instinctively known that while was a better choices. Either would have worked, but while was cleaner. Every little bit helps.