-
Notifications
You must be signed in to change notification settings - Fork 0
/
Highschool_Sweetheats.php
62 lines (55 loc) · 1.77 KB
/
Highschool_Sweetheats.php
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
51
52
53
54
55
56
57
58
59
60
61
62
// Instructions
// In this exercise, you are going to help high school sweethearts profess their love on social media by generating an ASCII heart with their initials:
// ****** ******
// ** ** ** **
// ** ** ** **
// ** * **
// ** **
// ** J. K. + M. B. **
// ** **
// ** **
// ** **
// ** **
// ** **
// ** **
// ***
// *
// #1 - Get the name's first letter
// #2 - Format the first letter as an initial
// #3 - Split the full name into the first name and the last name
// #4 - Put the initials inside of the heart
<?php
class HighSchoolSweetheart
{
public function firstLetter(string $name): string
{
$stringWithNoSpaces = str_replace(' ', '', $name);
return $stringWithNoSpaces[0];
}
public function initial(string $name): string
{
return strtoupper($this->firstLetter($name)).'.';
}
public function initials(string $name): string
{
list($firstName, $lastName) = explode(' ', $name);
return implode(' ', [$this->initial($firstName), $this->initial($lastName)]);
}
public function pair(string $sweetheart_a, string $sweetheart_b): string
{
return ' ****** ******
** ** ** **
** ** ** **
** * **
** **
** ' . $this->initials($sweetheart_a) . ' + ' . $this->initials($sweetheart_b) . ' **
** **
** **
** **
** **
** **
** **
***
*';
}
}