Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active August 18, 2020 16:25
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/7f7c02ee0a439bad11e373dcdab88f82 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/7f7c02ee0a439bad11e373dcdab88f82 to your computer and use it in GitHub Desktop.
Just PHP FUN 079.
<?php
# https://www.codewars.com/kata/58259d9062cfb45e1a00006b Fun with lists: map.
function map($head, $f) {
if(!$head) return null;
$tmp = $head;
$ans = new Node($f($tmp->data));
$tmp1 = $ans;
while($tmp){
$tmp = $tmp->next;
if($tmp){
$tmp1->next = new Node($f($tmp->data));
$tmp1 = $tmp1->next;
}
}
return $ans;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment