diff options
| author | Nuno Vieira <nunovieira220@gmail.com> | 2021-02-12 01:47:08 +0000 |
|---|---|---|
| committer | Nuno Vieira <nunovieira220@gmail.com> | 2021-02-12 01:47:08 +0000 |
| commit | 9609f2e04ee3392b068f5200c3beaddec432df6c (patch) | |
| tree | 2718d5a6129c37e812dffb56a44da0a9c3d23a4c | |
| parent | dc7f4663f21944c4200251e7dee2e6c4b844338c (diff) | |
| download | perlweeklychallenge-club-9609f2e04ee3392b068f5200c3beaddec432df6c.tar.gz perlweeklychallenge-club-9609f2e04ee3392b068f5200c3beaddec432df6c.tar.bz2 perlweeklychallenge-club-9609f2e04ee3392b068f5200c3beaddec432df6c.zip | |
Add nunovieira220 js solution to challenge 099
| -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)); |
