diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-06-27 10:32:03 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-27 10:32:03 +0100 |
| commit | f15c3866d4a44ed59a4c944fbe94d03d40a24538 (patch) | |
| tree | 9843c4b6fe90591dbb34ee4054d1a97c0c457a81 | |
| parent | c3852631228ee5b90d567d8e721ece1e0a7acaee (diff) | |
| parent | 5158c631ac06ce02ea26b2edc790ea64474b39e8 (diff) | |
| download | perlweeklychallenge-club-f15c3866d4a44ed59a4c944fbe94d03d40a24538.tar.gz perlweeklychallenge-club-f15c3866d4a44ed59a4c944fbe94d03d40a24538.tar.bz2 perlweeklychallenge-club-f15c3866d4a44ed59a4c944fbe94d03d40a24538.zip | |
Merge pull request #10331 from kaiburgdorf/challenge-275
Challenge 275
| -rw-r--r-- | challenge-275/kai-burgdorf/js/ch-1.js | 42 | ||||
| -rw-r--r-- | challenge-275/kai-burgdorf/js/ch-2.js | 25 |
2 files changed, 67 insertions, 0 deletions
diff --git a/challenge-275/kai-burgdorf/js/ch-1.js b/challenge-275/kai-burgdorf/js/ch-1.js new file mode 100644 index 0000000000..aeac25d88b --- /dev/null +++ b/challenge-275/kai-burgdorf/js/ch-1.js @@ -0,0 +1,42 @@ +//You are given a sentence, $sentence and list of broken keys @keys. +// +//Write a script to find out how many words can be typed fully. +// +//Example 1 +//Input: $sentence = "Perl Weekly Challenge", @keys = ('l', 'a') +//Output: 0 +//Example 2 +//Input: $sentence = "Perl and Raku", @keys = ('a') +//Output: 1 +// +//Only Perl since the other word two words contain 'a' and can't be typed fully. +//Example 3 +//Input: $sentence = "Well done Team PWC", @keys = ('l', 'o') +//Output: 2 +//Example 4 +//Input: $sentence = "The joys of polyglottism", @keys = ('T') +//Output: 2 + + + +possibleToType( 'Perl Wekkly Challenge', ['l', 'a']); +possibleToType( 'Perl and Raku', ['a']); +possibleToType( 'Well done Team PWC', ['l', 'o']); +possibleToType( 'The joys of polyglottism', ['T']); + + + +function possibleToType(sentence, brokenKeys) { + console.log("sentence: " + sentence + " ; Broken Keys: " + JSON.stringify(brokenKeys)) + let counter = 0; + sentence.split(" ").forEach((word, i) => { + let hasBrokenKeyLetter = true; + brokenKeys.forEach((key, i) => { + if(word.includes(key)) hasBrokenKeyLetter = false; + }) + if(hasBrokenKeyLetter) counter++; + + }) + console.log("Result: " +counter); +} + diff --git a/challenge-275/kai-burgdorf/js/ch-2.js b/challenge-275/kai-burgdorf/js/ch-2.js new file mode 100644 index 0000000000..379e61f6eb --- /dev/null +++ b/challenge-275/kai-burgdorf/js/ch-2.js @@ -0,0 +1,25 @@ +const input = "a1c1e1"; +//const input = "a1b2c3d4"; +//const input = "b2b"; +//const input = "a16z"; + +//close your eyes from corner cases :D + +let charArr = input.split(""); +let result = ""; + +charArr.forEach((singleChar, i) => { + if(singleChar.match(/[0-9]/g) && i > 0) { + result += convertToChar(result[i-1], singleChar); + } + else { + result +=singleChar; + } +}); + +console.log("input: " + input + " result: " + result); + + +function convertToChar(predecessor, shiftOffset) { + return String.fromCharCode((parseInt(predecessor.charCodeAt(0)) + parseInt(shiftOffset))); +} |
