Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active June 19, 2020 10:12
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/49948062a00b74b6e2bef4fd41ddcd3e to your computer and use it in GitHub Desktop.
Save lbvf50mobile/49948062a00b74b6e2bef4fd41ddcd3e to your computer and use it in GitHub Desktop.
Just PHP FUN 028.
<?php
# https://www.codewars.com/kata/5c44b0b200ce187106452139 How many arguments.
function args_count(...$x){ return count($x);}
<?php
# https://www.codewars.com/kata/526c7363236867513f0005ca Leap Years.
function isLeapYear($year) {
return (0 == $year%400) || (0 == $year%4 && 0 != $year%100);
}

Just PHP FUN 028.

Started at 14:41 19.06.2020 June Friday.
Finished at 17:10 19.06.2020 June Friday. (2hrs 29 minutes)

<?php
# https://www.codewars.com/kata/51c89385ee245d7ddf000001 Substituting Variables Into Strings: Padded Numbers.
function solution($value){
// Make it green, than make it clean :)
return "Value is ".str_pad($value,5,'0',STR_PAD_LEFT);
};
<?php
# https://www.codewars.com/kata/5259b20d6021e9e14c0010d4 Reverse words.
function reverseWords($str) {
return implode(" ",array_map('strrev',explode(" ",$str)));
}
<?php
# https://www.codewars.com/kata/56ed20a2c4e5d69155000301 Scaling Squared Strings.
function scale($s, $k, $n) {
$s = preg_replace('/[^\n]/',str_repeat('$0',$k), "$s\n");
$s = preg_replace('/\w+\s/',str_repeat('$0',$n), $s);
return trim($s);
}
# rjksn
# -------------------------------------------------------------------------------
function scale($s, $k, $n) {
if(empty($s)) return "";
return implode("\n",array_map(function($x) use ($k,$n){return words($x,$k,$n);}, explode("\n",$s)));
}
function chars($w, $k){
$arr = str_split($w);
$arr = array_map(function($x) use ($k){ return str_repeat($x,$k);},$arr);
return implode($arr);
}
function words($w,$k,$n){
return trim(str_repeat(chars($w,$k)."\n",$n));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment