-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstring_task.php
More file actions
38 lines (33 loc) · 1.42 KB
/
string_task.php
File metadata and controls
38 lines (33 loc) · 1.42 KB
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
<?php
// 7 kyu - String Task
// Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting of uppercase and lowercase Latin letters, it:
//
// deletes all the vowels,
// inserts a character "." before each consonant,
// replaces all uppercase consonants with corresponding lowercase ones.
// Vowels are letters "A", "O", "Y", "E", "U", "I", and the rest are consonants. The program's input is exactly one string, it should return the output as a single string, resulting after the program's processing the initial string.
//
// Input:
// The first argument represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters.
//
// Output:
// Return the resulting string.
//
// Examples:
//
// ('tour') => '.t.r'
// ('Codewars') => '.c.d.w.r.s'
// ('aBAcAba') => '.b.c.b'
function string_task(string $s): string {
return preg_replace_callback( '/./', function ($l) {
return '.' . $l[0];
}, preg_replace('/[aeiouy]/i', '', strtolower($s)));
}
// Alternative Solution:
// function string_task(string $s): string {
// return preg_replace('/./', ".$0", preg_replace('/[aeiouy]/', '', strtolower($s)));
// }
// function string_task(string $s): string {
// return preg_replace(['/[aiyeuo]/', '/([^aiyeuo])/'], ['', '.$1'], strtolower($s));
// }
?>