I spent a long time trying to get a regex to work for part 2, but I have given up for the time being. Got a short couple of answers for this:
function testScoresp1() { const input = document.getElementsByTagName('pre')[0].innerHTML; const groups = input.split('\n\n'); return groups.map(group => new Set(group.replaceAll('\n', ''))).reduce((sum, group) => sum + group.size, 0); } function testScoresp2() { const input = document.getElementsByTagName('pre')[0].innerHTML; const groups = input.split('\n\n'); const alphabet = 'abcdefghijklmnopqrstuvwxyz'.split(''); return alphabet.reduce((sum, letter) => { return sum + groups.filter(group => group.trim().split('\n').every(line => line.indexOf(letter) > -1)).length; }, 0); }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I spent a long time trying to get a regex to work for part 2, but I have given up for the time being. Got a short couple of answers for this: