Advent of Code 2026: Day 1

It's time for this year's advent of code, and a chance to "brain code"!

You can view the problem at adventofcode.com/2026/day/1, my solution is listed below.

function day1(inputArr) {
    const seen = inputArr.reduce((acc, curr) => {
        if(acc[curr] !== undefined) acc[curr]++ 
        else acc[curr] = 1
        return acc
    }, {})

    const seenSortedByMostCommon = Object.keys(seen).toSorted((a, b) => seen[a] < seen[b] ? 1 : -1)
    const mostCommonMultiplied = seenSortedByMostCommon.slice(0, 3).reduce((acc, curr) => curr * acc)
    
    const seenSortedByLeastCommon = Object.keys(seen).toSorted((a, b) => seen[a] < seen[b] ? -1 : 1)
    const leastCommonMultiplied = seenSortedByLeastCommon.slice(0, 3).reduce((acc, curr) => curr * acc)

    return { mostCommonMultiplied, leastCommonMultiplied }
}

Until next time,

- Brian