Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active August 25, 2020 16:10
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/9ebe5e6d0fcba6b54838f2d337483165 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/9ebe5e6d0fcba6b54838f2d337483165 to your computer and use it in GitHub Desktop.
Just PHP FUN 085.
<?php
# https://www.codewars.com/kata/582041237df353e01d000084 Fun with lists: filter.
function filter($head, $p) {
for( ; $head && ! $p($head->data); $head = $head->next);
if(!$head) return null;
$prv = $head; $node = $head->next;
for( ; $node ; $node = $node->next)
if($p($node->data)){
$prv->next = $node;
$prv = $node;
}
$prv->next = null;
return $head;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment