Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active June 17, 2020 15:29
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/9c42cb3d06384abcf2cf2c9d651de0b3 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/9c42cb3d06384abcf2cf2c9d651de0b3 to your computer and use it in GitHub Desktop.
Just PHP FUN 026.
<?php
# https://www.codewars.com/kata/57e1857d333d8e0f76002169 Loose Change!
// Remember you have a CHANGE (constant) associative array to work with ;)
function changeCount($change) {
return sprintf("$%.2f",array_reduce(explode(" ", $change),function($acc,$v){ return $acc + CHANGE[$v];}));
}
<?php
# https://www.codewars.com/kata/58249d08b81f70a2fc0001a4 Return the closest number multiple of 10.
function closest_multiple_10($n) {
return round($n,-1);
}
# ------------------------------------------------------------------------------------------------
function closest_multiple_10($n) {
return $n%10 < 5 ? $n - $n%10 : $n - $n%10 + 10;
}
<?php
# https://www.codewars.com/kata/5700c9acc1555755be00027e All Inclusive?
function containAllRots($s, $arr) {
$h = array_flip($arr);
$times = strlen($s);
for($i = 0; $i < $times; $i++){
$s = substr($s,1).substr($s,0,1);
if(! isset($h[$s]) ) return false;
}
return true;
}

Just PHP FUN 026.

Started at 21:11 17.06.2020 Wednesday June.
Finished at 22:27 17.06.2020 Wednesday June. (1hr 16minutes)

<?php
# https://www.codewars.com/kata/5ba38ba180824a86850000f7 Simple remove duplicates.
function solve($arr) {
return array_values(array_reverse(array_unique(array_reverse($arr))));
}
<?php
# https://www.codewars.com/kata/5b37a50642b27ebf2e000010 Sum of a Beach.
function sumOfABeach($beach) {
return preg_match_all('/(sand)|(water)|(fish)|(sun)/i',$beach);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment