-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathreverser.php
More file actions
27 lines (25 loc) · 884 Bytes
/
reverser.php
File metadata and controls
27 lines (25 loc) · 884 Bytes
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
<?php
// 7 kyu - Reverse Letters in Sentence
// Take a sentence (string) and reverse each letter in each word in the sentence. Do not reverse the order of the words, just the letters in each word.
//
// If there is punctuation, it should be interpreted as a regular character; no special rules.
//
// If there is spacing before/after the input string, leave them there.
//
// String will always be defined.
//
// Example:
//
// "A fun little challenge!" => 'A nuf elttil !egnellahc'
//
// " A fun little challenge! "=> ' A nuf elttil !egnellahc '
//
// Addendum: Your function receives a writeable null-terminated string.
//
// Mutate the string in-place and return the sentence.
//
// For this kata, you are not required to allocate or de-allocate any memory.
function reverser(string $sentence): string {
return implode(' ', array_map('strrev', explode(' ', $sentence)));
}
?>