If one takes stock of the fact that for a list of numbers, the iterative procedure described in the Q amounts to using the excluded entry along with the average calculated in the previous step, then correcting for the current step exclusion in order to obtain the desired figures makes implementing a functional solution straightforward.
crawlingComparison[list_, comp_: Equal] := Module[{e0, rest = Rest[list], len = Length[list]-1},
e0 = {#[[1]], #[[-1]], comp[#[[1]], #[[-1]]]} &@{First[list], Mean[rest]};
FoldList[
With[{ej = #2, mj = #1[[2]] + #1[[1]]/len - #2/len},
{ej, mj, comp[ej, mj]}] &, e0, rest][[All, -1]]
]
(irrelevant note: I'm calling it crawlingComparison
because it feels like the preceding entry crawls up to the calculated mean figure and forces it to update itself.)
An example
using the list
provided in the Q:
crawlingComparison[list]
{False, False, True, False, False}
Another example
If the desired comparison operator is different from Equal
that can be accommodated using the second argument of crawlingComparison
:
Using as a comparison operator the function comp = (#1 - #2)^2 <= 1&
(just an arbitrary choice):
crawlingComparison[list, comp]
{False, False, True, False, False}
lst
have duplicate elements? $\endgroup$MeanFilter[lst, 2] - lst
? That way you can play with different smoothing filters, too (e.g.GaussianFilter
,MedianFilter
) $\endgroup$