Solving day 5 of Advent of Code 2021 in JavaScript

preview_player
Показать описание
Advent of Code is a website that releases a new programming puzzle every day between the 1st and the 25th of December.

0:00 Part 1
26:35 Part 2

Have fun!

Рекомендации по теме
Комментарии
Автор

Awesome code. I like that you didn't use a matrix but used a map to store the values. I also learn how to use new Map(). Pretty cool.

okhaeadeleye
Автор

Hey! Another quick question here - I was testing around with a few things in the code you wrote to clean up and format the code prior to implementing any logic. I noticed that you returned "{ x, y }" instead of "x, y" (LINE 11) and was curious as to why you did thus. So I tested a few things out in the console and found that a simplified example of:
'
x.map(point => {
const [x, y] = point.split(', ');
return x, y
})

'
with x = [5, 9] returns 9. I was thinking that the map method would return a new array with each "point" (x and y) effectively being "pushed" into the array returned from the map method, but only y is returned (what I thought: ['5', '9'] vs. what actually happened: ['9']). Do you know why this is the case? Thank you so much once again :)

griffinbaker