Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active August 19, 2020 15:08
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/df89b896ced7f90eabf52e85cc994fb7 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/df89b896ced7f90eabf52e85cc994fb7 to your computer and use it in GitHub Desktop.
Just PHP FUN 080.
<?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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment