From a2288d04fa5ff22cb213d200fe2372e74a4ec74f Mon Sep 17 00:00:00 2001 From: Kai Burgdorf Date: Wed, 26 Jun 2024 22:09:21 +0200 Subject: ch-1 solved --- challenge-275/kai-burgdorf/js/ch-1.js | 42 +++++++++++++++++++++++++++++++++++ challenge-275/kai-burgdorf/js/ch-2.js | 0 2 files changed, 42 insertions(+) create mode 100644 challenge-275/kai-burgdorf/js/ch-1.js create mode 100644 challenge-275/kai-burgdorf/js/ch-2.js 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 -- cgit