Problem 54380. Define the higher order function - foldl
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 commentsProblem Recent Solvers2
Suggested Problems
-
Find the peak 3n+1 sequence value
2407 Solvers
-
Pythagorean perfect squares: find the square of the hypotenuse and the length of the other side
52 Solvers
-
Find last non-zero in a given dimension
38 Solvers
-
Convert a numerical matrix into a cell array of strings
1630 Solvers
-
8374 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!