Created
December 3, 2020 04:41
-
-
Save AdamMescher/27865b9638e7224074ba56c983ec0507 to your computer and use it in GitHub Desktop.
2020 Advent of Code Day 02 Part One Solution in JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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