Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active October 17, 2020 16:00
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/46a2150cb0ef737095542f2a27ef2de5 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/46a2150cb0ef737095542f2a27ef2de5 to your computer and use it in GitHub Desktop.
Just PHP FUN 131.
<?php
# https://www.codewars.com/kata/596f28fd9be8ebe6ec0000c1 Wave Sorting.
function wave_sort(&$array){
$answer = []; $size = count($array);
sort($array);
for($i = 0; $i < $size; $i += 1){
if(0 == $i%2) {
array_push($answer,array_pop($array));
}
else {
array_push($answer, array_shift($array));
}
}
$x = draw($answer);
echo "$x \n";
array_push($array,...$answer);
return $array;
}
function draw($a){
$ans = "";
foreach($a as $k => $v){
$ans .= $v;
if(0 == $k%2) $ans .= ">=";
else $ans .= "<=";
}
return $ans;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment