Let $a > 0$.
Let $f(x) := 2 x \sin \frac{1}{x} - \cos \frac{1}{x}$ for $x \in [-a, 0) \cup (0, a]$ and $f(0) := 0$.
Prove that $f$ has the maximum value on $[-a, a]$.
My attempt is the following:
Let $b \in (0, a)$.
Then, $f$ has the maximum value $\max f_{[b, a]}$on $[b, a]$.
Let $-c \in (-a, 0)$.
Then, $f$ has the maximum value $\max f_{[-a, -c]}$ on $[-a, -c]$.
If we can choose $b$ and $-c$ such that if $x \in (-c, b)$, then $f(x) \leq \max\{\max f_{[b, a]}, \max f_{[-a, -c]}\}$, then the proof is done.
Here is a rough proof.
Fix $a$.
As stated in the comments, we need only consider the interval $[0,a]$.
Let $\alpha = \min \{ \frac{a}{2}, \frac{1}{4\pi} \}.$ We break up the interval into two sets $A=[0,\alpha]$ and $B=[\alpha,a]$. The set $B$ is compact, and $f(x)$ is continuous and bounded on $B$. Therefore, $f(x)$ attains a maximum on $B$, call it $f^\star$. $\forall x \in A, f^\star \ge f(x),$ so $f^\star$ is the maximum on $[0,a]$ and thus on $[-a,a]$.