For Part Two, we're asked to find every point that has a total distance to every input point of less than 10000. I didn't do anything fancy here, not even a use of .reduce() to turn my array of grid points into a number. Just good old for loops. My one optimization was in the innermost for loop, where I calculate the value of current, the total distance of the current point to every point in input. Since I only want the points that have current less than 10000, I include that as part of the condition in the loop. Once current hits 10000, I break out of the loop and go on to the next point.
let total = 0for (let x = 0; x <= xMax; x += 1) {for (let y = 0; y <= yMax; y += 1) {let current = 0for (let i = 0; i < input.length && current < 10000; i += 1) {current += Math.abs(input[i][0] - x) + Math.abs(input[i][1] - y)}if (current < 10000) total += 1}}console.log(total)
This makes me think I overcomplicated Part One, but I'm not going to do it again any time soon.