Define the higher order function - foldl - MATLAB Cody - MATLAB Central

Problem 54380. Define the higher order function - foldl

Difficulty:Rate
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
For more information on foldl visit : https://wiki.haskell.org/Foldr_Foldl_Foldl'

Solution Stats

100.0% Correct | 0.0% Incorrect
Last Solution submitted on Jun 25, 2025

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 Solvers4

Suggested Problems

More from this Author2

Community Treasure Hunt

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

Start Hunting!