Given a binary function f, a starting value a, and a list (row vector) xs of values, the higher order function foldl folds the function f through the list from left to right. Your task is to provide a definition for foldl. Consider a recursive definition for elegance. Non-recursive definitions would be just fine as well.
Refer to the following mechanism as an example:
foldl(f,[4,7,5,6],2)
= foldl(f,[11,5,6],2)
= foldl(f,[16,6],2)
= foldl(f,[22],2)
= f(22,2)
= 24

Solution Stats
Solution Comments
Show comments
Loading...
Problem Recent Solvers4
Suggested Problems
-
Sort a list of complex numbers based on far they are from the origin.
5798 Solvers
-
Program an exclusive OR operation with logical operators
750 Solvers
-
find the roots of a quadratic equation
241 Solvers
-
273 Solvers
-
Test Problem; Create a 5x5 array containing all ones
405 Solvers
More from this Author2
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!