Skip to content

Instantly share code, notes, and snippets.

@slofurno
Created April 20, 2017 13:16
Show Gist options
  • Save slofurno/485fa65863a004894dbcba781c2e4393 to your computer and use it in GitHub Desktop.
Save slofurno/485fa65863a004894dbcba781c2e4393 to your computer and use it in GitHub Desktop.
function length(xs) {
var max = 0
for(var i = 0; i < xs.length; i++) {
for(var j = i+1; j < xs.length; j++) {
if (card(xs[i], xs[j]) == xs[i].length + xs[j].length) {
var mul = xs[i].length * xs[j].length
max = mul > max ? mul : max
}
}
}
return max
}
function card(xs, ys) {
var seen = {}
;[xs,ys].forEach(xs => [].slice.call(xs).forEach(x => seen[x] = true))
return Object.keys(seen).length
}
console.log(length(["abcw", "baz", "foo", "bar", "xtfn", "abcdef"]), 16)
console.log(length(["a", "ab", "abc", "d", "cd", "bcd", "abcd"]), 4)
console.log(length(["a", "aa", "aaa", "aaaa"]), 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment