Why is the following method for solving a differential equation valid? My question is right at the end, but first some context and background are required; below is a question involving electromagnetism and the solution to it:

Consider the wave equation for linearly $x$ polarized waves travelling in the $\pm z$ directions:
$$\frac{\partial^2 E_x}{\partial t^2}=c^2\frac{\partial^2 E_x}{\partial z^2}\tag{1}$$
  The general solution to equation $(1)$ is 
  $$E_x= E_{+}(q)+ E_{-}(s)$$
$$\bbox[5px,border:2px solid green]{\text{where}\, E_{+} \text{and}\, E_{-} \text{are arbitrary functions}}.$$ $$q=z-ct$$ & $$s=z+ct$$
Calculate the general form of the magnetic field in terms of $E_{+}$ and $E_{-}$


Here is the solution:

We can obviously write $$B_y=B_{+}(q)+B_{-}(s)\tag{a}$$ and $$\frac{\partial  B_y}{\partial t}=-\frac{\partial E_x}{\partial z}\tag{b}$$ then $$\frac{\partial q}{\partial t}\Bigg |_z\cdot\frac{d B_{+}}{dq}+\frac{\partial s}{\partial t}\Bigg |_z\cdot\frac{d B_{-}}{ds}=-\left(\frac{\partial q}{\partial z}\Bigg |_t\cdot\frac{d E_{+}}{dq}+\frac{\partial s}{\partial z}\Bigg |_t\cdot\frac{d  E_{-}}{ds}\right)\tag{c}$$
$$\implies -c\frac{d B_{+}}{dq}+c\frac{d B_{-}}{ds}=-\frac{d E_{+}}{dq}-\frac{d E_{-}}{ds}\tag{d}$$
  therefore $$ B_y=\frac{1}{c}\left[ E_{+}(q)- E_{-}(s)\right]\tag{e}$$
$$\bbox[5px,border:2px solid red]{\text{where in the last step we have equated terms that depend only on}\, q: }$$
$$\bbox[5px,border:2px solid red]{-c\frac{d B_{+}}{dq}=-\frac{d E_{+}}{dq}}\tag{*}$$
$$\bbox[5px,border:2px solid red]{\text{and those that depend only on}\, s:}$$
$$\bbox[5px,border:2px solid red]{c\frac{d B_{-}}{ds}=-\frac{d E_{-}}{ds}}\tag{**}$$
$$\bbox[5px,border:2px solid red]{\text{and integrated appropriately}}.$$


In going from part $(\mathrm{d})$ to $(\mathrm{e})$ the author mentioned that the method boxed in red has been used. 
But since when can I simply equate terms according to the variable for which they are being differentiated? If we were equating vector components or the real/imaginary components of an equation then I could understand this approach. But this is simply not the case here. 
Could someone please explain to me how this method is justified?

EDIT:
I have already been given an answer to this question but I would just like to use the method given in this question to see if it is consistent with the given answer.
So from $(*)$
$$-c\int\frac{d B_{+}}{dq}dq=-\int \frac{d E_{+}}{dq}dq$$
$$\implies cB_{+}= E_{+} + k \implies \fbox{$B_{+}= \frac{E_{+}}{c} + \frac{k}{c}$}\tag{I}$$
where $k$ is a constant of the integration.
& from $(**)$
$$c\int\frac{d B_{-}}{ds}ds=-\int \frac{d E_{-}}{ds}ds$$
$$\implies cB_{-}= -E_{-} + \ell \implies \fbox{$B_{-}=-\frac{E_{-}}{c} + \frac{\ell}{c}$}\tag{II}$$
where $\ell$ is a constant of the integration.
Now adding $(\mathrm{I})$ & $(\mathrm{II})$ and using $(\mathrm{a})$, $B_y=B_{+}(q)+B_{-}(s)$, 
$$B_y=B_{+}(q)+B_{-}(s)=\frac{E_{+}}{c} + \frac{k}{c} - \frac{E_{-}}{c} + \frac{\ell}{c}=\frac{1}{c}\left(E_{+}-E_{-} + k + \ell\right)$$
Now since $E_{+}$ & $E_{-}$ are arbitrary functions as stated in the green box I may therefore absorb the integration constants into $E_{+}$ (or $E_{-}$) 
and hence,
$$\bbox[yellow]{B_y = \frac{1}{c}\left(E_{+}-E_{-}\right)}$$
 A: Write it as
$$
c\frac{dB_+}{dq} -\frac{dE+}{dq} = c\frac{dB_-}{ds} +\frac{dE_-}{ds} 
$$
This is of the form $f(q) = g(s)$. The only way that two functions of different variables can be equal at all values of those variables is for both of them to be constant. To see this, fix $s = 3$. $f(q) = g(3)$ for all $q$, so $f$ is constant. The same applies to $g$. So there must be some constant $C$ such that
$$
c\frac{dB_+}{dq} -\frac{dE+}{dq} = C = c\frac{dB_-}{ds} +\frac{dE_-}{ds}
$$
which implies
$$
c\frac{dB_+}{dq} = \frac{dE_+}{dq} + C\;\;\;\;;\;\;\;\;c\frac{dB_-}{ds} = -\frac{dE_-}{ds} + C.
$$
These are easily solved to give
$$
B_y = \frac{1}{c}\left[E_+(q) - E_-(s) + Cz\right].
$$
Now strictly speaking the authors skip the part where they show $C=0$, though it's kind of obvious from physical intuition. Mathematically you can get it from Ampere's Law,
$$
-\frac{\partial B_y}{\partial z} = \frac{1}{c^2}\frac{\partial E_x}{\partial t}.
$$
(In fact, this whole "functions of different variables" thing can be avoided entirely by using Ampere's Law and some linear algebra to separate the $q$ and $s$ functions instead.)
