Advent of code Day 1 - Javascript while loop abuse

twitter logo github logo ・1 min read

Yesterday I found a little time, to start the annual AOC.

Yes, I know, I am late to the party. But hey: Better late than never.

So, the first part was an easy warm up, just sum an array. Part 2 was a bit trickier. I came up with this - admittedly - somewhat "not clean" solution.

OTOH, I find it nonetheless readable in one way or the other.

const findDoubleFrequency = array => {
  const doubles = new Set();
  let acc = 0;
  while (
    !array.find(x => {
      acc += x;
      if (doubles.has(acc)) {
        return true;
      return false;
  ) {}
  return acc;
twitter logo DISCUSS
Classic DEV Post from Jan 13

Why is Linux Not More Popular on the Desktop?

Picture taken from wikipedia. There are issues when it comes to Linux being mo...

Thomas Junkツ profile image
I know things