Skip to content

Instantly share code, notes, and snippets.

@sclark39
Last active December 4, 2017 23:04
Show Gist options
  • Save sclark39/a3e9b7d1548e861450002677e76847a2 to your computer and use it in GitHub Desktop.
Save sclark39/a3e9b7d1548e861450002677e76847a2 to your computer and use it in GitHub Desktop.
Solution to the Advent of Code 2017 Day 4
// var passphrases = input.split('\n')
function countValid( passphrases, allowAnagrams )
{
return passphrases.reduce( (s,passphrase) => {
var passwords = passphrase.split(' ')
passwords = allowAnagrams ? passwords : passwords.map( a => ( a.split('').sort().join('') ) )
return s + passwords.reduce( ( s,n,i,a ) => s && a.indexOf(n) == i )
}, 0 )
}
@vjakovlev
Copy link

hey, i do the input, and made input.split like you instruct. How should i call the function and see the result?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment