- https://www.codewars.com/kata/577e277c9fb2a5511c00001d Vowel Shifting.
Started at 22:43 09.09.2020 Wednesday Sep.
Finished at 23:09 09.09.2020 Wednesday Sep. (0hrs 26minutes)
Started at 22:43 09.09.2020 Wednesday Sep.
Finished at 23:09 09.09.2020 Wednesday Sep. (0hrs 26minutes)
<?php | |
# https://www.codewars.com/kata/577e277c9fb2a5511c00001d Vowel Shifting. | |
function vowelShift($text, $n) { | |
if(0 == strlen($text)) return $text; | |
echo "$text $n \n"; | |
$arr = str_split($text); | |
$indices = []; $start = []; $end = []; | |
foreach($arr as $i=>$ch){ | |
if(preg_match('/[aeiou]/i',$ch)){ | |
array_push($indices, $i); | |
array_push($start,$ch); | |
array_push($end,$ch); | |
} | |
} | |
$size = count($start); | |
if(0 > $n) $n = $size - abs($n)%$size; | |
foreach($start as $i=>$v) $end[($i+$n)%$size] = $v; | |
foreach($indices as $i=>$v) $arr[$v] = $end[$i]; | |
return implode($arr); | |
} |