Skip to content

Instantly share code, notes, and snippets.

@webyroki
Created July 2, 2017 14:42
Show Gist options
  • Save webyroki/e2019aa3fabd90f7585c7bec851bdcb6 to your computer and use it in GitHub Desktop.
Save webyroki/e2019aa3fabd90f7585c7bec851bdcb6 to your computer and use it in GitHub Desktop.
solution('abc') // should return ['ab', 'c_'] solution('abcdef') // should return ['ab', 'cd', 'ef']
//solution('abc') should return ['ab', 'c_']
//solution('abcdef') should return ['ab', 'cd', 'ef']
function solution($str) {
$STR = str_split($str, 2);
foreach($STR as $key => $value){
$value = str_pad($value, 2, "_", STR_PAD_RIGHT);
$STR[$key] = $value;
}
return $STR;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment