- https://www.codewars.com/kata/58319f37aeb69a89a00000c7 Fun with lists: reduce.
Started at 21:50 19.08.2020 Wednesday Aug.
Finished at 22:08 19.08.2020 Wednesday Aug. (0hrs 18minutes)
Started at 21:50 19.08.2020 Wednesday Aug.
Finished at 22:08 19.08.2020 Wednesday Aug. (0hrs 18minutes)
<?php | |
# https://www.codewars.com/kata/58319f37aeb69a89a00000c7 Fun with lists: reduce. | |
function reduce($head, $f, $init) { | |
return $head ? reduce($head->next,$f, $f($init,$head->data)): $init; | |
} | |
# ------------------------------------------------------------------------------ | |
function reduce($head, $f, $init) { | |
while($head){ | |
$new = $f($init,$head->data); | |
echo "new ($init, $head->data) => $new\n"; | |
$init = $new; | |
$head = $head->next; | |
} | |
return $init; | |
} |