diff options
| author | Kai Burgdorf <k@iburgdorf.de> | 2024-06-26 22:09:21 +0200 |
|---|---|---|
| committer | Kai Burgdorf <k@iburgdorf.de> | 2024-06-26 22:09:21 +0200 |
| commit | a2288d04fa5ff22cb213d200fe2372e74a4ec74f (patch) | |
| tree | 39d602e2287e1958b8438533dae0b3960f068419 | |
| parent | c3852631228ee5b90d567d8e721ece1e0a7acaee (diff) | |
| download | perlweeklychallenge-club-a2288d04fa5ff22cb213d200fe2372e74a4ec74f.tar.gz perlweeklychallenge-club-a2288d04fa5ff22cb213d200fe2372e74a4ec74f.tar.bz2 perlweeklychallenge-club-a2288d04fa5ff22cb213d200fe2372e74a4ec74f.zip | |
ch-1 solved
| -rw-r--r-- | challenge-275/kai-burgdorf/js/ch-1.js | 42 | ||||
| -rw-r--r-- | challenge-275/kai-burgdorf/js/ch-2.js | 0 |
2 files changed, 42 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..e69de29bb2 --- /dev/null +++ b/challenge-275/kai-burgdorf/js/ch-2.js |
