Skip to content

Commit

Permalink
day 04, part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
tschulte committed Dec 10, 2018
1 parent 2164ad6 commit 3d54374
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions day04/javascript/tschulte/README.adoc
Expand Up @@ -46,3 +46,10 @@ And put it all together
....
include::solution.js[tags=part1]
....

== Second Star

[source, js]
....
include::solution.js[tags=part2]
....
13 changes: 13 additions & 0 deletions day04/javascript/tschulte/solution.js
Expand Up @@ -20,3 +20,16 @@ const overlappingTimes = overlappingSleepTimes(foundGuard);

console.log("Day 04, part 1: " + id * overlappingTimes[0].minute);
//end::part1[]

// tag::part2[]
const part2Guards = reduced
.map(guard => {
return { guard: guard, times: overlappingSleepTimes(guard) };
})
.filter(guard => guard.times.length > 0);
part2Guards.sort((a, b) => b.times[0].days - a.times[0].days);
const part2Guard = part2Guards[0];
console.log(
"Day 04, part 2: " + part2Guard.guard.guard * part2Guard.times[0].minute
);
// end::part2[]

0 comments on commit 3d54374

Please sign in to comment.