Intro 🌐
Today, I start a new series about code katas.
I will take interesting katas of all levels and explain how to solve them.
Probl...
For further actions, you may consider blocking this person and/or reporting abuse
Hi Abe,
nice solution, thanks!
All credit to this post! codereview.stackexchange.com/a/162... Been using this at work and loving it.
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!
Or a simple reduce for the functional way
numbers.reduce((acc,val)=>{
return (val%2===1 ? {...acc,odd:[...acc.odd,val]}:{...acc,even:[...acc.even,val]});
},{odd:[],even:[]})
I was just going to comment, that this would also be done with reduce (my favorite)
Hey there,
thanks for your solution!
Nice opportunity for people who want to step up their
reduce
-skills.Yeah, I would've gone with the reduce too, since that's only one iteration over the array, not two. Not sure I'd use spread though, wouldn't that kill the gain?
Probably it would, so just mutate the acc and return it, I think even after all the solutions, I think the simple for loop performs the best.