Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

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:

Code

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.

ideas.alanwsmith.com

Give one of those a shot and see how it works for you

For now, I'm going back to working on ASCII_BEAR