Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active June 15, 2020 10:21
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/bb9e992713419a6d1d615f38515bf9e4 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/bb9e992713419a6d1d615f38515bf9e4 to your computer and use it in GitHub Desktop.
Just PHP FUN 024.
<?php
# https://www.codewars.com/kata/5c55ad8c9d76d41a62b4ede3 Find all pairs.
function duplicates($array){
$h = array_count_values($array);
$get = function($x){ return ($x - $x%2)/2;};
return array_sum(array_map($get,array_values($h)));
}
#----------------------------------------------------------------------
function duplicates($array){
$h = []; $sum = 0;
foreach($array as $v){
if(!isset($h[$v])) $h[$v] = 0;
$h[$v] += 1;
}
foreach(array_values($h) as $v) $sum += ($v - $v%2)/2;
return $sum;
}
<?php
# https://www.codewars.com/kata/597c684822bc9388f600010f FIXME: Get Full Name.
class Dinglemouse {
public function __construct($firstName, $lastName) {
$this->firstName = $firstName;
$this->lastName = $lastName;
$this->x = [$this->firstName, $this->lastName];
}
public function getFullName() {
return implode(' ',array_filter($this->x));
}
}

Just PHP FUN 024.

Started at 14:40 15.06.2020 Monday June.
Finishe at 17:20 15.06.2020 Monday June. (2hrs 40minutes)

<?php
# https://www.codewars.com/kata/5656b6906de340bd1b0000ac Two to One.
function longest($a, $b) {
return count_chars($a.$b,3);
} # jovan91, citricsquid, SolidDev, Drazyhaze, Kev.JL, mylkydad (plus 29 more warriors)
#------------------------------------------------------------------------
function longest($a, $b) {
$x = array_unique(str_split($a.$b)); sort($x);
return implode($x);
}
<?php
# https://www.codewars.com/kata/56f3a1e899b386da78000732 Parts of a list.
function partlist($arr) {
$ans = [];
for($i = 0; $i < count($arr) - 1; $i++){
array_push($ans,[implode(" ",array_slice($arr,0,$i+1)),implode(" ",array_slice($arr,$i+1))]);
}
return $ans;
}
<?php
# https://www.codewars.com/kata/58b8c94b7df3f116eb00005b Simple Fun #176: Reverse Letter.
function reverseLetter($str){
return strrev(preg_replace('/[^a-z]/','',$str));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment