Skip to content

Instantly share code, notes, and snippets.

@davidino
Last active February 4, 2017 06:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidino/de9825fa0e08eeb9abb5a18f343ce245 to your computer and use it in GitHub Desktop.
Save davidino/de9825fa0e08eeb9abb5a18f343ce245 to your computer and use it in GitHub Desktop.
Js - Katas
function LCS(x, y) {
if (x.length == 0 | y.length == 0)
return '';
var res = []
x = x.split('');
y = y.split('');
y.forEach((ago, i) => {
x.forEach((pag, j) => {
if (pag.indexOf(ago) >= 0 && res.indexOf(ago) == -1) {
res.push(ago)
}
});
});
return res.join('');
}
function pascal(depth) {
if (depth === 1) {
return [[1]]
}
var result = [];
var stack = [];
var rest = []
for ( var i = 0 ; i < depth ; i++) {
var j = i;
while(j >= 0 ) {
if (j ==0 || j == i) {
stack.push(1);
} else {
stack.push(rest[j] + rest[j-1]);
}
j--;
}
result.push(stack);
rest = stack;
stack = [];
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment