Skip to content

Instantly share code, notes, and snippets.

@AdamMescher
Created December 3, 2020 04:41
Show Gist options
  • Save AdamMescher/27865b9638e7224074ba56c983ec0507 to your computer and use it in GitHub Desktop.
Save AdamMescher/27865b9638e7224074ba56c983ec0507 to your computer and use it in GitHub Desktop.
2020 Advent of Code Day 02 Part One Solution in JavaScript
String.prototype.count = function(char) {
return (this.length - this.replace(new RegExp(char,"g"), '').length) / s1.length
}
input.reduce((accum, item) => {
const charMin = item[0].split('-')[0]
const charMax = item[0].split('-')[1]
const char = item[1]
const password = item[2]
const charCount = password.count(char)
if (charCount <= charMax && charCount >= charMin) {
accum++
}
return accum
}, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment