Skip to content

Instantly share code, notes, and snippets.

@Gerst20051
Last active April 6, 2016 16:20
Show Gist options
  • Save Gerst20051/ba4773202f555d5f82f9 to your computer and use it in GitHub Desktop.
Save Gerst20051/ba4773202f555d5f82f9 to your computer and use it in GitHub Desktop.
CodeFights Solutions
// https://codefights.com/challenge/wwPuroz78u6yA8cGD
function Expand_It(s, k) {
return s.match(/\w\d+/g).sort().reduce(function (a, b) {
return a + b[0].repeat(+b.slice(1));
}, '')[k - 1] || '-1';
}
function Expand_It(s, k) {
return s.match(/.\d+/g).sort().find(function (a) {
return (k -= a.slice(1)) < 1;
})[0];
}
function Expand_It(s, k) {
e = s.match(/\w\d+/g).sort()
for (v in e)
if ((k -= e[v].slice(1)) <= 0) return e[v][0]
}
Expand_It = (s, k) => s.match(/.\d+/g).sort().find(a => (k -= a.slice(1)) < 1)[0]
Expand_It('z2b13a5c2', 10); // b
https://codefights.com/challenge/z6jikHZ7iumoDB86m/main
a = (n, d) => d ? n * a(--n, --d) : 1
SumItUp = s = (n, k, d) => {
if (!d) d = n + 1
return k ? a(++n, d) + s(n, --k, d) : 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment