forked from vsb-vaj/template-lab-2024s-01
-
Notifications
You must be signed in to change notification settings - Fork 0
/
task-strings.js
50 lines (42 loc) · 1.54 KB
/
task-strings.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Check functions which could help you solve these tasks https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
// 1 =================================
// Write function to parameterize a string.
// Example:
// console.log(parametrize("Javascript is the best"));
// "javascript-is-the-best"
// Your code:
const parametrize = (input) => {
return input.toLowerCase().replaceAll(" ", "-");
};
// 2 =================================
// Write function that takes object and return sentence
// Example:
// giveSentenceForPerson({name: "Obi-wan", position: "Jedi", age: 40, location: "Starwars universe"})
// ➞ Hello Obi-wan from Starwars universe! It is nice to meet you! You look awesome for your 40, young Jedi!
// Your code:
const giveSentenceForPerson = (obj) => {
return `Hello ${obj.name} from ${obj.location}! It is nice to meet you! You look awesome for your ${obj.age}, young ${obj.position}!`;
};
// 3 =================================
// Write function that takes string and replace all `a`, `e`, `i`, `o` with *
// Example:
// replace("Hello Javascript") ➞ "H*ll* J*v*scr*pt"
// Your code:
const replace = (input) => {
return input.replaceAll(RegExp("[aeio]", "g"), "*");
};
function test() {
console.log(parametrize("Javascript is the best"));
console.log("--------------");
console.log(
giveSentenceForPerson({
name: "Obi-wan",
position: "Jedi",
age: 40,
location: "Starwars universe",
}),
);
console.log("--------------");
console.log(replace("Hello Javascript"));
}
// test();