Last active
January 5, 2016 16:15
-
-
Save ghaiklor/6a607d0bbd1df5c811b4 to your computer and use it in GitHub Desktop.
Advent of Code (Day 5 Part 2)
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
const fs = require('fs'); | |
const INPUT = fs.readFileSync('./input.txt', 'utf-8').split('\n'); | |
// Part 1 was written with pure functions but Part 2 I've decided to write with RegExp | |
const isContainPair = string => /([a-z][a-z]).*\1/.test(string); | |
const isContainRepeatLetter = string => /([a-z])[a-z]\1/.test(string); | |
const isNiceString = string => !!(isContainPair(string) && isContainRepeatLetter(string)); | |
const result = INPUT.reduce((total, string) => isNiceString(string) ? ++total : total, 0); | |
console.log(result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment