|
| 1 | +// You received a whatsup message from an unknown number. Could it be from that girl/boy with a foreign accent you met yesterday evening? |
| 2 | +// |
| 3 | +// Write a simple function to check if the string contains the word hallo in different languages. |
| 4 | +// |
| 5 | +// These are the languages of the possible people you met the night before: |
| 6 | +// |
| 7 | +// hello - english |
| 8 | +// ciao - italian |
| 9 | +// salut - french |
| 10 | +// hallo - german |
| 11 | +// hola - spanish |
| 12 | +// ahoj - czech republic |
| 13 | +// czesc - polish |
| 14 | +// Notes |
| 15 | +// |
| 16 | +// you can assume the input is a string. |
| 17 | +// to keep this a beginner exercise you don't need to check if the greeting is a subset of word (Hallowen can pass the test) |
| 18 | +// function should be case insensitive to pass the tests |
| 19 | + |
| 20 | +const langs = [ |
| 21 | + { greeting: "hello", language: "english" }, |
| 22 | + { greeting: "ciao", language: "italian" }, |
| 23 | + { greeting: "salut", language: "french" }, |
| 24 | + { greeting: "hallo", language: "german" }, |
| 25 | + { greeting: "hola", language: "spanish" }, |
| 26 | + { greeting: "ahoj", language: "czech republic" }, |
| 27 | + { greeting: "czesc", language: "polish" }, |
| 28 | +] |
| 29 | + |
| 30 | +const tests = [ |
| 31 | + { str: "well, hellomygoodsir", output: true }, |
| 32 | + { str: "meh", output: false }, |
| 33 | + { str: "das ein race, hallo", output: true} |
| 34 | +] |
| 35 | + |
| 36 | +function validateHello(greetings) { |
| 37 | + for ( let i = 0; i < langs.length; i++) { |
| 38 | + const re = new RegExp(langs[i].greeting, "ig"); |
| 39 | + if (re.test(greetings)) { |
| 40 | + return true; |
| 41 | + } |
| 42 | + } |
| 43 | + return false; |
| 44 | +} |
| 45 | + |
| 46 | +tests.forEach((test) => { |
| 47 | + console.log(`is: ${validateHello(test.str)}, should be: ${test.output}`); |
| 48 | +}); |
| 49 | + |
0 commit comments