filter all galaxies and positions

This commit is contained in:
Baipyrus 2023-12-12 10:14:25 +01:00
parent 8b72c18d65
commit d1c56a4317

View File

@ -21,7 +21,11 @@ const flip = (current) =>
); );
const universe = flip(expand(flip(expand(input)))); const universe = flip(expand(flip(expand(input))));
console.log(universe); const galaxies = universe
.map((a, y) => a.map((b, x) => ({ s: b, x, y })).filter((b) => b.s === "#"))
.filter((e) => e.length > 0)
.reduce((a, i) => [...a, ...i], []);
console.log(galaxies);
const t1 = performance.now(); const t1 = performance.now();
console.log(`Runtime: ${t1 - t0}ms`); console.log(`Runtime: ${t1 - t0}ms`);