DEV Community

Discussion on: Daily Challenge #114 - Speed Control

Collapse
 
peter279k profile image
peter279k

Here is the PHP code snippets:

function gps($s, $x) {
  $hourlySpeed = [];

  $index = 1;
  for (; $index<count($x); $index+=1) {
    $hourlySpeed[] = round(($x[$index] - $x[$index-1]) * 3600 / $s, 1);
  }

  $ans = $hourlySpeed[0];
  $index = 1;
  for (; $index<count($hourlySpeed); $index+=1) {
    if ($hourlySpeed[$index] - $hourlySpeed[$index-1] <= 0) {
      continue;
    }

    if ($ans < $hourlySpeed[$index]) {
      $ans = $hourlySpeed[$index];
    }
  }

  return $ans;
}