The function being used is (meant to be) accumulator = element / accumulator for this test. Are you using the args in the right order? This test is from the problem specs repo.
I thought foldLeft used parentheses to group to the left, and naturally iterating elements from left to right, where on each iteration the accumulator is always the left operand and the collection element is right one.
For example foldl from Haskell has following signature:
foldl :: (b -> a -> b) -> b -> t a -> b
where b is the type of the accumulator and returning value, and a is a type of element in the collection t a and can be interpreted as:
foldl :: (acc -> element -> acc) -> initial_acc -> [element] -> result
If accumulator and element are flipped, we won’t get classic left folding:
4 / (3 / (2 / (1 / 24))) ~> 64
which doesn’t look like left folding: parentheses used to group to the right (right folding), but elements are iterated from left to right (left folding).
Eg Haskell’s foldr:
foldr :: (a -> b -> b) -> b -> t a -> b
foldr :: (element -> acc -> acc) -> initial_acc -> [element] -> result
1 / 2 / 3 / 4 / 24 ~>
1 / ( 2 / (3 / (4 / 24)))
Good that @yura could reveal some of their assumptions:
It is not a requirement because it is “natural” and Haskell does it like this
Guessing a functions parameter meaning from a known usage by position is not safe
Anyways, I think the “illogic” was introduced ~6 months ago when an update to the exercise did 2 things at once - replace manual code with a template and update the tests to the latest problem specifications. Problem specifications intentionally flipped and renamed the operands from (x,y) => x/y to (acc,el) => el/acc. But the change in the Swift track did not revert the operands inside the passed in function to { $1 / $0 } to meet that. So now the students have to pass in reverted parameters to acheive the expected result: (el, acc) => el/acc.
We can definitely fix that. I will create the PR in a few days, as I’d like to polish some other aspects of this exercise as well. However, I think it would be appreciated if @yura made the changes himself, if he intends to do so.
What would be the impact of fixing this?
Students would need to change the order in which they pass arguments to the closure.