If every point is a local maximum, is it a step function?

What are the functions $f:\mathbb R\to\mathbb R$ such that every point is a local maximum?

Certainly, $f(x)=c$ works for every constant. So does $\lfloor x\rfloor$, as does $I_{\{0\}}(x)=\begin{cases}1&x=0\\0&x\ne0\end{cases}$. Another example is the oddly beautiful $e^{-\lfloor1/\lvert x\rvert\rfloor^{-2}}$. Question is, are step functions such as these the only ones? Are there any examples where every point is a strict local maximum?

(Thomae's function is a near-miss, since the condition doesn't hold on irrational points. Although, most points are irrational, so I guess the term "near-miss" doesn't quite fit.)

EDIT: My definition of step-function is the sum of countably many indicator functions of intervals, $\sum_{n=0}^\infty a_nI_{A_n}(x)$. If it were uncountable, any function would be step, as $\{\alpha\}$ is an interval ($[\alpha,\alpha]$).

This arose when I was thinking about the topological space with basis $\{(-\infty,a]:a\in\mathbb R\}$. If you call that space $X$, then the continuous functions $f:\mathbb R\to X$ are precisely these. I don't have a formal proof but I'm pretty sure (and this would belong in a different question anyway).

Contrast with: Is $f$ constant if every point is local maximum or local minimum of $f$?


Although, I cannot provide a more general answer, I will derive one property of your set of functions: Their image is at most countable.

To see this, let $f$ be such a function. We will construct an injective map $\text{Im}(f) \to \mathbb Q \times \mathbb Q$ (for which we need the Axiom of Choice). This map goes as follows: Let $y \in \text{Im}(f)$. Map this to one $x$ such that $f(x)=y$. Now there's an open interval $I$ around $x$ such that $f(\tilde{x}) \leq f(x)$ for all $\tilde{x}$ in $I$. In particular, there also exists a closed interval $J\subset I$ with rational endpoints with this property. We now map $x$ to $J$ and thus to $\mathbb Q \times \mathbb Q$ (i.e. to the left and right end points of $J$ respectively).

It remains to show that this mapping is injective. Let $y$,$\tilde{y}$ which both get mapped to the same interval $J$. Also let $x$,$\tilde{x}$ such that $f(x)=y$, $f(\tilde{x})=\tilde{y}$. Now in this interval by construction it holds both that $f(x) \leq f(\tilde{x})$ and $f(\tilde{x}) \leq f(x)$. Thus $f(x)=f(\tilde{x})$ and finally $y=\tilde{y}$ which shows that the mapping is injective.