From d8eca467b5baedc4f78ae4f7c1ff4e48f7a5b7ba Mon Sep 17 00:00:00 2001 From: ReenExe Date: Mon, 13 Mar 2017 23:38:58 +0200 Subject: [PATCH] pass tests (#16) --- src/Dashatizer.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Dashatizer.php b/src/Dashatizer.php index 06729db..1268343 100644 --- a/src/Dashatizer.php +++ b/src/Dashatizer.php @@ -4,8 +4,16 @@ class Dashatizer { - public function dashatize(int $num): string + public function dashatize(int $number): string { + $digits = str_split($number); + $result = []; + + foreach ($digits as $digit) { + $result[] = $digit & 1 ? "-$digit-" : $digit; + } + + return trim(str_replace('--', '-', implode('', $result)), '-'); } }