diff options
| -rw-r--r-- | challenge-099/nunovieira220/js/ch-1.js | 10 | ||||
| -rw-r--r-- | challenge-099/nunovieira220/js/ch-2.js | 18 |
2 files changed, 28 insertions, 0 deletions
diff --git a/challenge-099/nunovieira220/js/ch-1.js b/challenge-099/nunovieira220/js/ch-1.js new file mode 100644 index 0000000000..5e41fd4c11 --- /dev/null +++ b/challenge-099/nunovieira220/js/ch-1.js @@ -0,0 +1,10 @@ +// Input +const S = 'abcde'; +const P = 'a*c?e'; + +// Pattern Match +const regex = P.replace(/(\?|\*)/g, '.$1'); +const res = S.match(new RegExp(`^${regex}$`, "g")); + +// Output +console.log(res ? 1 : 0); diff --git a/challenge-099/nunovieira220/js/ch-2.js b/challenge-099/nunovieira220/js/ch-2.js new file mode 100644 index 0000000000..368b8a3fce --- /dev/null +++ b/challenge-099/nunovieira220/js/ch-2.js @@ -0,0 +1,18 @@ +// Unique Subsequence +const counter = (S, T) => { + if(!T.length || !S.length) return 0; + + const index = S.indexOf(T.substring(0, 1)); + const last = T.length === 1 ? 1 : 0; + + if(index === -1) return 0; + + return last + counter(S.substring(index + 1), T) + counter(S.substring(index + 1), T.substring(1)); +} + +// Input +const S = 'littleit'; +const T = 'lit'; + +// Output +console.log(counter(S, T)); |
