Created
October 10, 2017 20:30
-
-
Save KimSarabia/88d4f9adb58bf894172d70f1608a6811 to your computer and use it in GitHub Desktop.
Best Travel
This file contains hidden or 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
// Work in Progress | |
function chooseBestSum(t, k, ls) { | |
if(ls.length <= 1){return null} | |
else { | |
return Array | |
.apply(0, { length: Math.pow(k+1, ls.length) }) | |
.map(Number.call, Number) | |
.map(a => a | |
.toString(ls.length) | |
.split('') | |
.sort() | |
.filter((a, b, c) => c.indexOf(a) == b) | |
.join('')) | |
.filter((a, b, c) => a.length == k && c.indexOf(a) == b) | |
.map(x => x.split('').map(y => ls[+y])) | |
.map(x => x.reduce((pv,cv) => pv+cv, 0)) | |
.filter(x => x <= t) | |
.reduce((a,b) => Math.max(a,b)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment