Last active
February 4, 2017 06:57
-
-
Save davidino/de9825fa0e08eeb9abb5a18f343ce245 to your computer and use it in GitHub Desktop.
Js - Katas
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 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(''); | |
} |
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 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