codewars set reducer solution
...Oof
I did my first codewars problem today. SchipThatcode was doing one on stream. I figured I'd give it a shot too.
Fuck me.
It took four hours.
It was the Set Reducer problem. Here's what I ended up with:
const input = [2, 4, 4, 6, 2, 1, 1, 5,
6, 7, 8, 8, 8, 8, 9, 0, 1, 1, 5, 4, 4]
const musher = (input) => {
if (input.length > 1) {
let counter = 1
for (let i = 0; i < input.length; i++) {
if (input[i] != input[i+1]){
input[i] = counter
counter = 1
} else {
input[i] = -1
counter += 1
}
}
return musher(input.filter((n) => n >= 0))
} else {
return input
}
}
console.log(musher(input))
I haven't looked at all the other ways to do it. I'm sure there are more... pick your adjective... approaches. I don't really care. These things aren't for me.
Creative Coding
I love coding. I spend most of my time hacking away on things. But, coding is a means to an end. What I really love is making things. And at the end of those four hours, I have nothing to show for it. I didn't actually make anything.
I'm glad I did one because I like trying new things, but I don't expect to be doing any more.
I hear a lot of folks ask about ideas for projects to do instead of things like codewars. Something practical to spend their time on. If you're in need of inspiration I made a little side with a ton of ideas on it.
Give one of those a shot and see how it works for you
For now, I'm going back to working on ASCII_BEAR
Notes
-
First off: You should totally follow Schip's stream. It's awesome
-
If you love codewars, I'm legit happy you've found something you're into. It genuinely looks cool. It's just not for me
-
I very much speaking from a position of privilege. Specifically, I'm not having to practice this kind of stuff in prep for technical interviews. Based on today, I'm not sure I could get past one even though I'm not half bad at throwing around ones and zeros
-
Apologies for the lack of syntax highlighting in the code sample. I'm in the process of building a new static site generator and haven't gotten to that yet.