diff options
| author | Nuno Vieira <nunovieira220@gmail.com> | 2021-01-21 23:05:48 +0000 |
|---|---|---|
| committer | Nuno Vieira <nunovieira220@gmail.com> | 2021-01-21 23:05:48 +0000 |
| commit | 8943cd3305ee9d3400427451d6a9d197e399c6d1 (patch) | |
| tree | 75de6a3e136c929ea3f44bc888361c14aa6262b8 | |
| parent | a82c0c8a3e188cc1d9b4c6d4379d072a902948c1 (diff) | |
| download | perlweeklychallenge-club-8943cd3305ee9d3400427451d6a9d197e399c6d1.tar.gz perlweeklychallenge-club-8943cd3305ee9d3400427451d6a9d197e399c6d1.tar.bz2 perlweeklychallenge-club-8943cd3305ee9d3400427451d6a9d197e399c6d1.zip | |
Add nunovieira220 js solution to challenge 096
| -rw-r--r-- | challenge-096/nunovieira220/js/ch-1.js | 9 | ||||
| -rw-r--r-- | challenge-096/nunovieira220/js/ch-2.js | 19 |
2 files changed, 28 insertions, 0 deletions
diff --git a/challenge-096/nunovieira220/js/ch-1.js b/challenge-096/nunovieira220/js/ch-1.js new file mode 100644 index 0000000000..5480a7f9ba --- /dev/null +++ b/challenge-096/nunovieira220/js/ch-1.js @@ -0,0 +1,9 @@ +// Input +const S = ' Perl and Raku are part of the same family '; + +// Reverse Words +const trimmed = S.trim().replace(/\s+/g, ' '); +const res = trimmed.split(' ').reverse().join(' '); + +// Output +console.log(res);
\ No newline at end of file diff --git a/challenge-096/nunovieira220/js/ch-2.js b/challenge-096/nunovieira220/js/ch-2.js new file mode 100644 index 0000000000..33eb9566f3 --- /dev/null +++ b/challenge-096/nunovieira220/js/ch-2.js @@ -0,0 +1,19 @@ +// Input +const s1 = 'kitten'; +const s2 = 'sitting'; + +// Edit Distance +const maxLength = Math.max(s1.length, s2.length); + +for(let i = 0; i < maxLength; i++) { + const char1 = s1.charAt(i); + const char2 = s2.charAt(i); + + if(char1 && char2) { + console.log(`Replace '${char1}' with '${char2}'`); + } else if (char1) { + console.log(`Remove '${char1}' at position ${$i + 1}`); + } else { + console.log(`Insert '${char2}' at the end`); + } +}
\ No newline at end of file |
