DEV Community

loading...

Discussion on: Daily Challenge #16 - Number of People on the Bus

Collapse
p810 profile image
Payton Bice • Edited

PHP 7.4:

$bus = fn(array $stops, int $riders = 0): int => array_reduce($stops, fn(int $count, array $data): int => ($count + $data[0]) - $data[1], $riders);

var_dump($bus([[1, 0], [2, 1], [5, 3], [4, 2]])); //=> int(6)