Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active September 9, 2020 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lbvf50mobile/af00175188286a3ee308a0e596b04e8e to your computer and use it in GitHub Desktop.
Save lbvf50mobile/af00175188286a3ee308a0e596b04e8e to your computer and use it in GitHub Desktop.
Just PHP FUN 098.
<?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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment