The problem with katas is that they ignore the 'why' of the problem.
Since we don't know why we're doing this, let's delegate that problem to the caller as much as possible.
This is really a classification problem.
const splitNumber = (numbers, emitEven, emitOdd) => numbers.forEach(n => (n % 2 ? emitOdd : emitEven)(number));
Now we can defer the arrangement of the classified numbers to someone else.
If they want to store them in arrays, then they can do that.
const even = []; const odd = []; splitNumber(numbers, n => even.push(n), n => odd.push(n));
But that's their problem.
Nice analysis
Hi,
thanks for your insights, interesting question to think about!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
The problem with katas is that they ignore the 'why' of the problem.
Since we don't know why we're doing this, let's delegate that problem to the caller as much as possible.
This is really a classification problem.
Now we can defer the arrangement of the classified numbers to someone else.
If they want to store them in arrays, then they can do that.
But that's their problem.
Nice analysis
Hi,
thanks for your insights,
interesting question to think about!