Created
April 20, 2017 13:16
-
-
Save slofurno/485fa65863a004894dbcba781c2e4393 to your computer and use it in GitHub Desktop.
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
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