Skip to content

Commit d63d5b2

Browse files
committed
simple challenges
1 parent 18d40a9 commit d63d5b2

5 files changed

Lines changed: 95 additions & 1 deletion

File tree

CodeWars/6kyu/Amidakuji/script2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,4 @@ function amidakuji2(ar) {
114114
}
115115
}, n);
116116
}
117-
}
117+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "didshesayhallo",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC"
12+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "doyouspeakenglish",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "script.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC"
12+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Given a string of arbitrary length with any ascii characters. Write a function to determine whether the string contains the whole word "English".
2+
//
3+
// The order of characters is important -- a string "abcEnglishdef" is correct but "abcnEglishsef" is not correct.
4+
//
5+
// Upper or lower case letter does not matter -- "eNglisH" is also correct.
6+
//
7+
// Return value as boolean values, true for the string to contains "English", false for it does not.
8+
const testSentences = [
9+
{ sentence: 'abcEnglishdef', output: true },
10+
{ sentence: 'dkfj kdjfeNglisHdkhglkd', output: true },
11+
{ sentence: 'aadegnlishuyee', output: false }
12+
];
13+
14+
function spEng(sentence){
15+
const re = /(english)/ig;
16+
return re.test(sentence);
17+
}
18+
19+
for (let i = 0; i < testSentences.length; i++) {
20+
console.log(`is: ${spEng(testSentences[i].sentence)}, should be: ${testSentences[i].output}`);
21+
}

0 commit comments

Comments
 (0)