- https://www.codewars.com/kata/58259d9062cfb45e1a00006b Fun with lists: map.
Started at 22:52 18.08.2020 Tuesday Aug.
Finished at 23:25 18.08.2020 Tueaday Aug. (0hrs 33minutes)
Started at 22:52 18.08.2020 Tuesday Aug.
Finished at 23:25 18.08.2020 Tueaday Aug. (0hrs 33minutes)
<?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; | |
} |