Reduce - Map-Reduce - MATLAB Cody - MATLAB Central

Problem 595. Reduce - Map-Reduce

Difficulty:Rate

Write reduce function, that takes arguments and constantly folds results into next call argument, finally returning a value; i.e. for a binary operator Fb,

     reduce(Fb,{a,b,c},start_val) = F(F(F(start_val,a),b),c)

Same can be done for a n-ary operators.

Eg. reduce(@strcat,{'foo','bar','baz','bat'},' ') = reduce(@plus,{1,2,3,4},0) = 10 reduce(@max,{1,2,3,4},{5,6,7,8},5) = 8

Remember, we use cell arrays for passing arguments, not matrices!

Solution Stats

42.86% Correct | 57.14% Incorrect
Last Solution submitted on Feb 28, 2023

Problem Comments

Solution Comments

Show comments
Why should you share code?
In a discussion on LInkedin about my recent blog post, Do these...
3
6

Problem Recent Solvers17

Suggested Problems

More from this Author10

Problem Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!