Started at 23:10 2020.11.12 Thursday.
Finished at 23:37 2020.11.13 Friday.
Last active
November 13, 2020 16:37
-
-
Save lbvf50mobile/143dc5ea1ce14c6d0b6b99e22f22b2e3 to your computer and use it in GitHub Desktop.
Just PHP FUN 150.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function pickPeaks(array $arr) { | |
$size = count($arr); | |
//echo implode(",",$arr)."\n"; | |
$pos = []; $peaks = []; $prv = $arr[0]; | |
for($i = 1; $i <= $size-2; $i += 1){ | |
$cr = $arr[$i]; | |
$cr_i = $i; | |
$nxt = $arr[$i+1]; | |
while($nxt == $cr && $i <= $size - 2) { | |
$nxt = $arr[$i+1]; | |
if($nxt != $cr) break; | |
//echo "- $i $nxt ($size);\n"; | |
$i += 1; | |
} | |
if($prv < $cr && $cr > $nxt){ | |
array_push($pos,$cr_i); | |
array_push($peaks,$cr); | |
} | |
$prv = $cr; | |
} | |
return ['pos' => $pos, 'peaks' => $peaks]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment